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(keywords: nil, **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.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/paapi/client.rb', line 10 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.keys.include?(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? if defined?(HTTPX) @http = HTTPX.plugin(:persistent) elsif defined?(HTTP) @http = HTTP::Client.new else @http = nil end end |
Instance Attribute Details
#access_key ⇒ Object (readonly)
Returns the value of attribute access_key.
8 9 10 |
# File 'lib/paapi/client.rb', line 8 def access_key @access_key end |
#condition ⇒ Object
Returns the value of attribute condition.
7 8 9 |
# File 'lib/paapi/client.rb', line 7 def condition @condition end |
#http ⇒ Object (readonly)
Returns the value of attribute http.
8 9 10 |
# File 'lib/paapi/client.rb', line 8 def http @http end |
#market ⇒ Object
Returns the value of attribute market.
8 9 10 |
# File 'lib/paapi/client.rb', line 8 def market @market end |
#marketplace ⇒ Object
Returns the value of attribute marketplace.
7 8 9 |
# File 'lib/paapi/client.rb', line 7 def marketplace @marketplace end |
#partner_tag ⇒ Object
Returns the value of attribute partner_tag.
7 8 9 |
# File 'lib/paapi/client.rb', line 7 def partner_tag @partner_tag end |
#partner_type ⇒ Object (readonly)
Returns the value of attribute partner_type.
8 9 10 |
# File 'lib/paapi/client.rb', line 8 def partner_type @partner_type end |
#resources ⇒ Object
Returns the value of attribute resources.
7 8 9 |
# File 'lib/paapi/client.rb', line 7 def resources @resources end |
#secret_key ⇒ Object (readonly)
Returns the value of attribute secret_key.
8 9 10 |
# File 'lib/paapi/client.rb', line 8 def secret_key @secret_key end |
Instance Method Details
#get_browse_nodes(browse_node_ids:, **options) ⇒ Object
66 67 68 69 |
# File 'lib/paapi/client.rb', line 66 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
45 46 47 48 |
# File 'lib/paapi/client.rb', line 45 def get_items(item_ids:, **) payload = { ItemIds: Array(item_ids), Resources: @resources }.merge() request(op: :get_items, payload: payload) end |
#get_variations(asin:, **options) ⇒ Object
50 51 52 53 |
# File 'lib/paapi/client.rb', line 50 def get_variations(asin:, ** ) payload = { ASIN: asin, Resources: @resources }.merge() request(op: :get_variations, payload: payload) end |
#search_items(keywords: nil, **options) ⇒ Object
TODO: Currently we assume Keywords, but we need one of the following: [Keywords Actor Artist Author Brand Title ]
56 57 58 59 60 61 62 63 64 |
# File 'lib/paapi/client.rb', line 56 def search_items(keywords: nil, ** ) raise ArgumentError("Missing keywords") unless (.keys | SEARCH_PARAMS).length.positive? search_index = .dig(:SearchIndex) ||'All' payload = { Keywords: keywords, Resources: @resources, ItemCount: 10, ItemPage: 1, SearchIndex: search_index }.merge() request(op: :search_items, payload: payload) end |