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
3 changed files with 15 additions and 11 deletions

View File

@@ -11,7 +11,6 @@ module Paapi
SEARCH_PARAMS = %i[keywords actor, artist, author, brand title].freeze
DEFAULT_PARTNER_TYPE = 'Associates'
DEFAULT_MARKET = :us
DEFAULT_CONDITION = 'Any'
DEFAULT_RESOURCES = [
'Images.Primary.Large',
'ItemInfo.ByLineInfo',
@@ -73,7 +72,6 @@ module Paapi
:partner_type,
:market,
:partner_market,
:condition,
:resources,
:test_mode

View File

@@ -1,17 +1,16 @@
require 'http'
require 'net/http'
require 'aws-sigv4'
module Paapi
class Client
attr_accessor :partner_tag, :marketplace, :resources, :condition
attr_accessor :partner_tag, :marketplace, :resources
attr_reader :partner_type, :access_key, :secret_key, :market
def initialize(access_key: Paapi.access_key,
secret_key: Paapi.secret_key,
partner_tag: Paapi.partner_tag,
market: Paapi.market || DEFAULT_MARKET,
condition: Paapi.condition || DEFAULT_CONDITION,
resources: Paapi.resources || DEFAULT_RESOURCES,
partner_type: DEFAULT_PARTNER_TYPE
)
@@ -21,7 +20,7 @@ module Paapi
@secret_key = secret_key
@partner_type = partner_type
@resources = resources unless resources.nil?
@condition = condition
self.market = market
@partner_tag = partner_tag if !partner_tag.nil?
end
@@ -73,7 +72,6 @@ module Paapi
}
default_payload = {
'Condition' => condition,
'PartnerTag' => partner_tag,
'PartnerType' => partner_type,
'Marketplace' => marketplace.site
@@ -100,9 +98,18 @@ module Paapi
headers['Authorization'] = signature.headers['authorization']
headers['Content-Type'] = 'application/json; charset=utf-8'
Response.new( HTTP.headers(headers).post(endpoint, json: payload ) )
end
Response.new( Client.post(url: endpoint, body: payload, headers: headers))
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

View File

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