I have two very similar methods, which make HTTP requests, the difference is that one makes PUT and another GET. Is there any proper Ruby way not to repeat the setup code and not to pass the flag parameter?
def notify_client(url, params)
uri = URI.parse(url)
https = Net::HTTP.new(uri.host, uri.port)
https.use_ssl = !Rails.env.development?
req = Net::HTTP::Patch.new(uri.path)
req.body = {data: {attributes: params}}.to_json
res = https.request(req)
puts "Response #{res.code} #{res.message}: #{res.body}"
end
def notify_vendor(url, params)
uri = URI.parse(url)
https = Net::HTTP.new(uri.host, uri.port)
https.use_ssl = !Rails.env.development?
req = Net::HTTP::Get.new(uri.path)
req.body = {data: {attributes: params}}.to_json
res = https.request(req)
puts "Response #{res.code} #{res.message}: #{res.body}"
end
Net::HTTP::Patch
? \$\endgroup\$