mirror of
https://github.com/dkam/paapi.git
synced 2025-12-28 15:14:52 +00:00
Compare commits
6 Commits
add_condit
...
net_http
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ba6a52ce9c | ||
|
|
747e76fe8f | ||
|
|
6115f72119 | ||
|
|
e47add0064 | ||
|
|
a86acb1ef9 | ||
|
|
706a9fb377 |
@@ -11,7 +11,6 @@ module Paapi
|
|||||||
SEARCH_PARAMS = %i[keywords actor, artist, author, brand title].freeze
|
SEARCH_PARAMS = %i[keywords actor, artist, author, brand title].freeze
|
||||||
DEFAULT_PARTNER_TYPE = 'Associates'
|
DEFAULT_PARTNER_TYPE = 'Associates'
|
||||||
DEFAULT_MARKET = :us
|
DEFAULT_MARKET = :us
|
||||||
DEFAULT_CONDITION = 'Any'
|
|
||||||
DEFAULT_RESOURCES = [
|
DEFAULT_RESOURCES = [
|
||||||
'Images.Primary.Large',
|
'Images.Primary.Large',
|
||||||
'ItemInfo.ByLineInfo',
|
'ItemInfo.ByLineInfo',
|
||||||
@@ -73,7 +72,6 @@ module Paapi
|
|||||||
:partner_type,
|
:partner_type,
|
||||||
:market,
|
:market,
|
||||||
:partner_market,
|
:partner_market,
|
||||||
:condition,
|
|
||||||
:resources,
|
:resources,
|
||||||
:test_mode
|
:test_mode
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,16 @@
|
|||||||
require 'http'
|
require 'net/http'
|
||||||
require 'aws-sigv4'
|
require 'aws-sigv4'
|
||||||
|
|
||||||
module Paapi
|
module Paapi
|
||||||
class Client
|
class Client
|
||||||
|
|
||||||
attr_accessor :partner_tag, :marketplace, :resources, :condition
|
attr_accessor :partner_tag, :marketplace, :resources
|
||||||
attr_reader :partner_type, :access_key, :secret_key, :market
|
attr_reader :partner_type, :access_key, :secret_key, :market
|
||||||
|
|
||||||
def initialize(access_key: Paapi.access_key,
|
def initialize(access_key: Paapi.access_key,
|
||||||
secret_key: Paapi.secret_key,
|
secret_key: Paapi.secret_key,
|
||||||
partner_tag: Paapi.partner_tag,
|
partner_tag: Paapi.partner_tag,
|
||||||
market: Paapi.market || DEFAULT_MARKET,
|
market: Paapi.market || DEFAULT_MARKET,
|
||||||
condition: Paapi.condition || DEFAULT_CONDITION,
|
|
||||||
resources: Paapi.resources || DEFAULT_RESOURCES,
|
resources: Paapi.resources || DEFAULT_RESOURCES,
|
||||||
partner_type: DEFAULT_PARTNER_TYPE
|
partner_type: DEFAULT_PARTNER_TYPE
|
||||||
)
|
)
|
||||||
@@ -21,7 +20,7 @@ module Paapi
|
|||||||
@secret_key = secret_key
|
@secret_key = secret_key
|
||||||
@partner_type = partner_type
|
@partner_type = partner_type
|
||||||
@resources = resources unless resources.nil?
|
@resources = resources unless resources.nil?
|
||||||
@condition = condition
|
|
||||||
self.market = market
|
self.market = market
|
||||||
@partner_tag = partner_tag if !partner_tag.nil?
|
@partner_tag = partner_tag if !partner_tag.nil?
|
||||||
end
|
end
|
||||||
@@ -73,7 +72,6 @@ module Paapi
|
|||||||
}
|
}
|
||||||
|
|
||||||
default_payload = {
|
default_payload = {
|
||||||
'Condition' => condition,
|
|
||||||
'PartnerTag' => partner_tag,
|
'PartnerTag' => partner_tag,
|
||||||
'PartnerType' => partner_type,
|
'PartnerType' => partner_type,
|
||||||
'Marketplace' => marketplace.site
|
'Marketplace' => marketplace.site
|
||||||
@@ -100,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
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user