6 Commits

Author SHA1 Message Date
Dan Milne
ba6a52ce9c Paapi will always use HTTPS 2020-08-21 18:06:00 +10:00
Dan Milne
747e76fe8f Require net/http and set the body to JSON 2020-08-21 17:58:56 +10:00
Dan Milne
6115f72119 Move the HTTP request code into a method and remove references to the HTTP gem 2020-08-21 17:45:47 +10:00
Dan Milne
e47add0064 Comment out unused Gem 2020-08-21 16:58:18 +10:00
Dan Milne
a86acb1ef9 Merge branch 'master' into net_http 2020-08-21 16:55:54 +10:00
Dan Milne
706a9fb377 Investigate a plain net::http client for less dependancies 2020-01-10 15:37:36 +11:00
2 changed files with 13 additions and 5 deletions

View File

@@ -1,4 +1,4 @@
require 'http' require 'net/http'
require 'aws-sigv4' require 'aws-sigv4'
module Paapi module Paapi
@@ -98,9 +98,18 @@ 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
end end
def self.post(url:, body:, headers:)
uri = URI.parse(url)
request = Net::HTTP::Post.new(uri)
request.content_type = 'application/json; charset=UTF-8'
headers.each { |k, v| request[k] = v }
request.body = body.to_json
Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
http.request(request)
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