mirror of
https://github.com/dkam/paapi.git
synced 2025-12-28 15:14:52 +00:00
Compare commits
2 Commits
net_http
...
add_condit
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
316e71ee46 | ||
|
|
8bd8ba1e84 |
@@ -11,6 +11,7 @@ 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',
|
||||||
@@ -72,6 +73,7 @@ module Paapi
|
|||||||
:partner_type,
|
:partner_type,
|
||||||
:market,
|
:market,
|
||||||
:partner_market,
|
:partner_market,
|
||||||
|
:condition,
|
||||||
:resources,
|
:resources,
|
||||||
:test_mode
|
:test_mode
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,17 @@
|
|||||||
require 'net/http'
|
require 'http'
|
||||||
require 'aws-sigv4'
|
require 'aws-sigv4'
|
||||||
|
|
||||||
module Paapi
|
module Paapi
|
||||||
class Client
|
class Client
|
||||||
|
|
||||||
attr_accessor :partner_tag, :marketplace, :resources
|
attr_accessor :partner_tag, :marketplace, :resources, :condition
|
||||||
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
|
||||||
)
|
)
|
||||||
@@ -20,7 +21,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
|
||||||
@@ -72,6 +73,7 @@ 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
|
||||||
@@ -98,18 +100,9 @@ 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( Client.post(url: endpoint, body: payload, headers: headers))
|
Response.new( HTTP.headers(headers).post(endpoint, json: payload ) )
|
||||||
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,5 +31,6 @@ 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