Move the HTTP request code into a method and remove references to the HTTP gem

This commit is contained in:
Dan Milne
2020-08-21 17:45:47 +10:00
parent e47add0064
commit 6115f72119
2 changed files with 5 additions and 8 deletions

View File

@@ -1,4 +1,3 @@
#require 'http'
require 'aws-sigv4' require 'aws-sigv4'
module Paapi module Paapi
@@ -98,20 +97,19 @@ module Paapi
headers['Authorization'] = signature.headers['authorization'] headers['Authorization'] = signature.headers['authorization']
headers['Content-Type'] = 'application/json; charset=utf-8' headers['Content-Type'] = 'application/json; charset=utf-8'
#Response.new( HTTP.headers(headers).post(endpoint, json: payload ) ) Response.new( Client.post(url: endpoint, body: payload, headers: headers))
end
request = Net::HTTP::Post.new(endpoint) def self.post(url:, body:, headers:)
uri = URI.parse(url)
request = Net::HTTP::Post.new(uri)
request.content_type = 'application/json; charset=UTF-8' request.content_type = 'application/json; charset=UTF-8'
headers.each { |k, v| request[k] = v } headers.each { |k, v| request[k] = v }
request.body = body request.body = body
req_options = { use_ssl: uri.scheme == 'https' } req_options = { use_ssl: uri.scheme == 'https' }
Net::HTTP.start(uri.hostname, uri.port, req_options) do |http| Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
http.request(request) http.request(request)
end end
end end
end end
end end

View File

@@ -31,6 +31,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'byebug', '~> 11' spec.add_development_dependency 'byebug', '~> 11'
spec.add_development_dependency 'awesome_print', '~> 1.8' spec.add_development_dependency 'awesome_print', '~> 1.8'
spec.add_dependency 'http', '~> 4'
spec.add_dependency 'aws-sigv4', '~> 1' spec.add_dependency 'aws-sigv4', '~> 1'
end end