Class: Paapi::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/paapi/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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.

Raises:

  • (ArgumentError)


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_keyObject (readonly)

Returns the value of attribute access_key.



8
9
10
# File 'lib/paapi/client.rb', line 8

def access_key
  @access_key
end

#conditionObject

Returns the value of attribute condition.



7
8
9
# File 'lib/paapi/client.rb', line 7

def condition
  @condition
end

#httpObject (readonly)

Returns the value of attribute http.



8
9
10
# File 'lib/paapi/client.rb', line 8

def http
  @http
end

#marketObject

Returns the value of attribute market.



8
9
10
# File 'lib/paapi/client.rb', line 8

def market
  @market
end

#marketplaceObject

Returns the value of attribute marketplace.



7
8
9
# File 'lib/paapi/client.rb', line 7

def marketplace
  @marketplace
end

#partner_tagObject

Returns the value of attribute partner_tag.



7
8
9
# File 'lib/paapi/client.rb', line 7

def partner_tag
  @partner_tag
end

#partner_typeObject (readonly)

Returns the value of attribute partner_type.



8
9
10
# File 'lib/paapi/client.rb', line 8

def partner_type
  @partner_type
end

#resourcesObject

Returns the value of attribute resources.



7
8
9
# File 'lib/paapi/client.rb', line 7

def resources
  @resources
end

#secret_keyObject (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:, **options)
  payload = { BrowseNodeIds: Array(browse_node_ids), Resources:  @resources }.merge(options)
  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:, **options)
  payload = { ItemIds: Array(item_ids), Resources:  @resources }.merge(options)
  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:, **options )
  payload = { ASIN: asin, Resources:  @resources }.merge(options)
  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, **options )
  raise ArgumentError("Missing keywords") unless (options.keys | SEARCH_PARAMS).length.positive?

  search_index = options.dig(:SearchIndex) ||'All'

  payload = { Keywords: keywords, Resources:  @resources, ItemCount: 10, ItemPage: 1, SearchIndex: search_index }.merge(options)

  request(op: :search_items, payload: payload)
end