Class: Paapi::Client
- Inherits:
-
Object
- Object
- Paapi::Client
- Defined in:
- lib/paapi/client.rb
Instance Attribute Summary collapse
-
#access_key ⇒ Object
readonly
Returns the value of attribute access_key.
-
#condition ⇒ Object
Returns the value of attribute condition.
-
#http ⇒ Object
readonly
Returns the value of attribute http.
-
#market ⇒ Object
Returns the value of attribute market.
-
#marketplace ⇒ Object
Returns the value of attribute marketplace.
-
#partner_tag ⇒ Object
Returns the value of attribute partner_tag.
-
#partner_type ⇒ Object
readonly
Returns the value of attribute partner_type.
-
#resources ⇒ Object
Returns the value of attribute resources.
-
#secret_key ⇒ Object
readonly
Returns the value of attribute secret_key.
Instance Method Summary collapse
- #get_browse_nodes(browse_node_ids:, **options) ⇒ Object
- #get_items(item_ids:, **options) ⇒ Object
- #get_variations(asin:, **options) ⇒ Object
-
#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) ⇒ Client
constructor
A new instance of Client.
-
#search_items(**options) ⇒ Object
TODO: Currently we assume Keywords, but we need one of the following: [Keywords Actor Artist Author Brand Title ].
Constructor Details
#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) ⇒ Client
Returns a new instance of Client.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/paapi/client.rb', line 9 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 ) raise ArgumentError unless MARKETPLACES.key?(market.to_sym) @access_key = access_key @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? @http = Net::HTTP::Persistent.new(name: "paapi").tap do |c| c.open_timeout = 2 c.read_timeout = 5 c.write_timeout = 5 end end |
Instance Attribute Details
#access_key ⇒ Object (readonly)
Returns the value of attribute access_key.
7 8 9 |
# File 'lib/paapi/client.rb', line 7 def access_key @access_key end |
#condition ⇒ Object
Returns the value of attribute condition.
6 7 8 |
# File 'lib/paapi/client.rb', line 6 def condition @condition end |
#http ⇒ Object (readonly)
Returns the value of attribute http.
7 8 9 |
# File 'lib/paapi/client.rb', line 7 def http @http end |
#market ⇒ Object
Returns the value of attribute market.
7 8 9 |
# File 'lib/paapi/client.rb', line 7 def market @market end |
#marketplace ⇒ Object
Returns the value of attribute marketplace.
6 7 8 |
# File 'lib/paapi/client.rb', line 6 def marketplace @marketplace end |
#partner_tag ⇒ Object
Returns the value of attribute partner_tag.
6 7 8 |
# File 'lib/paapi/client.rb', line 6 def partner_tag @partner_tag end |
#partner_type ⇒ Object (readonly)
Returns the value of attribute partner_type.
7 8 9 |
# File 'lib/paapi/client.rb', line 7 def partner_type @partner_type end |
#resources ⇒ Object
Returns the value of attribute resources.
6 7 8 |
# File 'lib/paapi/client.rb', line 6 def resources @resources end |
#secret_key ⇒ Object (readonly)
Returns the value of attribute secret_key.
7 8 9 |
# File 'lib/paapi/client.rb', line 7 def secret_key @secret_key end |
Instance Method Details
#get_browse_nodes(browse_node_ids:, **options) ⇒ Object
65 66 67 68 |
# File 'lib/paapi/client.rb', line 65 def get_browse_nodes(browse_node_ids:, **) payload = {BrowseNodeIds: Array(browse_node_ids), Resources: @resources}.merge() request(op: :get_browse_nodes, payload: payload) end |
#get_items(item_ids:, **options) ⇒ Object
43 44 45 46 |
# File 'lib/paapi/client.rb', line 43 def get_items(item_ids:, **) payload = {"PartnerTag" => partner_tag, "PartnerType" => "Associates", ItemIds: Array(item_ids), Resources: @resources}.merge() request(op: :get_items, payload: payload) end |
#get_variations(asin:, **options) ⇒ Object
48 49 50 51 |
# File 'lib/paapi/client.rb', line 48 def get_variations(asin:, **) payload = {ASIN: asin, Resources: @resources}.merge() request(op: :get_variations, payload: payload) end |
#search_items(**options) ⇒ Object
TODO: Currently we assume Keywords, but we need one of the following: [Keywords Actor Artist Author Brand Title ]
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/paapi/client.rb', line 54 def search_items(**) .transform_keys!(&:to_s) raise ArgumentError.new("Missing keywords") unless (.keys & SEARCH_PARAMS).length.positive? search_index = .dig(:SearchIndex) || "All" payload = {"PartnerTag" => partner_tag, "PartnerType" => "Associates", "Resources" => @resources, "ItemCount" => 10, "ItemPage" => 1, "SearchIndex" => search_index}.merge() request(op: :search_items, payload: payload) end |