Class: Vacuum::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/vacuum/request.rb

Overview

A request to the Amazon Product Advertising API

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(marketplace: :us, access_key: , secret_key: , partner_tag: , partner_type: ) ⇒ Request

Creates a new request

Parameters:

  • marketplace (Symbol, String) (defaults to: :us)
  • access_key (String) (defaults to: )
  • secret_key (String) (defaults to: )
  • partner_tag (String) (defaults to: )
  • partner_type (String) (defaults to: )

Raises:


30
31
32
33
# File 'lib/vacuum/request.rb', line 30

def initialize(marketplace: :us, **args)
  @locale = Locale.new(marketplace, **args)
  @client = HTTP::Client.new
end

Instance Attribute Details

#clientHTTP::Client (readonly)

Returns:

  • (HTTP::Client)

13
14
15
# File 'lib/vacuum/request.rb', line 13

def client
  @client
end

#localeLocale (readonly)

Returns:


16
17
18
# File 'lib/vacuum/request.rb', line 16

def locale
  @locale
end

#operationOperation (readonly)

Returns:


19
20
21
# File 'lib/vacuum/request.rb', line 19

def operation
  @operation
end

Instance Method Details

#get_browse_nodes(browse_node_ids: , languages_of_preference: nil, marketplace: nil, partner_tag: nil, partner_type: nil, resources: nil) ⇒ Response

Returns details about specified browse nodes

Parameters:

  • browse_node_ids (Array<String,Integer>, String, Integer) (defaults to: )
  • languages_of_preference (Array<String>, nil) (defaults to: nil)
  • marketplace (String, nil) (defaults to: nil)
  • partner_tag (String, nil) (defaults to: nil)
  • partner_type (String, nil) (defaults to: nil)
  • resources (Array<String>, nil) (defaults to: nil)

Returns:

See Also:


46
47
48
49
# File 'lib/vacuum/request.rb', line 46

def get_browse_nodes(browse_node_ids:, **params)
  params.update(browse_node_ids: Array(browse_node_ids))
  request('GetBrowseNodes', params)
end

#get_items(condition: nil, currency_of_preference: nil, item_id_type: nil, item_ids: , languages_of_preference: nil, marketplace: nil, merchant: nil, offer_count: nil, partner_tag: nil, partner_type: nil, resources: nil) ⇒ Response

Returns the attributes of one or more items

Parameters:

  • condition (String, nil) (defaults to: nil)
  • currency_of_preference (String, nil) (defaults to: nil)
  • item_id_type (String, nil) (defaults to: nil)
  • item_ids (Array<String>, String) (defaults to: )
  • languages_of_preference (Array<String>, nil) (defaults to: nil)
  • marketplace (String, nil) (defaults to: nil)
  • merchant (String, nil) (defaults to: nil)
  • offer_count (Integer, nil) (defaults to: nil)
  • partner_tag (String, nil) (defaults to: nil)
  • partner_type (String, nil) (defaults to: nil)
  • resources (Array<String>, nil) (defaults to: nil)

Returns:

See Also:


67
68
69
70
# File 'lib/vacuum/request.rb', line 67

def get_items(item_ids:, **params)
  params.update(item_ids: Array(item_ids))
  request('GetItems', params)
end

#get_variations(asin: , condition: nil, currency_of_preference: nil, languages_of_preference: nil, marketplace: nil, merchant: nil, offer_count: nil, partner_tag: nil, partner_type: nil, resources: nil, variation_count: nil, variation_page: nil) ⇒ Response

Returns a set of items that are the same product, but differ according to a consistent theme

Parameters:

  • asin (String) (defaults to: )
  • condition (String, nil) (defaults to: nil)
  • currency_of_preference (String, nil) (defaults to: nil)
  • languages_of_preference (Array<String>, nil) (defaults to: nil)
  • marketplace (String, nil) (defaults to: nil)
  • merchant (String, nil) (defaults to: nil)
  • offer_count (Integer, nil) (defaults to: nil)
  • partner_tag (String, nil) (defaults to: nil)
  • partner_type (String, nil) (defaults to: nil)
  • resources (Array<String>, nil) (defaults to: nil)
  • variation_count (Integer, nil) (defaults to: nil)
  • variation_page (Integer, nil) (defaults to: nil)

Returns:

See Also:


90
91
92
# File 'lib/vacuum/request.rb', line 90

def get_variations(**params)
  request('GetVariations', params)
end

#persistent(timeout: 5) ⇒ self

Flags as persistent

Parameters:

  • timeout (Integer) (defaults to: 5)

Returns:

  • (self)

130
131
132
133
134
135
# File 'lib/vacuum/request.rb', line 130

def persistent(timeout: 5)
  host = "https://#{locale.host}"
  @client = client.persistent(host, timeout: timeout)

  self
end

#search_items(actor: nil, artist: nil, author: nil, availability: nil, brand: nil, browse_node_id: nil, condition: nil, currency_of_preference: nil, delivery_flags: nil, item_count: nil, item_page: nil, keywords: nil, languages_of_preference: nil, marketplace: nil, max_price: nil, merchant: nil, min_price: nil, min_reviews_rating: nil, min_savings_percent: nil, offer_count: nil, partner_tag: nil, partner_type: nil, resources: nil, search_index: nil, sort_by: nil, title: nil) ⇒ Response

Searches for items on Amazon based on a search query

Parameters:

  • actor (String, nil) (defaults to: nil)
  • artist (String, nil) (defaults to: nil)
  • availability (String, nil) (defaults to: nil)
  • brand (String, nil) (defaults to: nil)
  • browse_node_id (Integer, nil) (defaults to: nil)
  • condition (String, nil) (defaults to: nil)
  • currency_of_preference (String, nil) (defaults to: nil)
  • delivery_flags (Array<String>, nil) (defaults to: nil)
  • item_count (Integer, nil) (defaults to: nil)
  • item_page (Integer, nil) (defaults to: nil)
  • keywords (String, nil) (defaults to: nil)
  • languages_of_preference (Array<String>, nil) (defaults to: nil)
  • max_price (Integer, nil) (defaults to: nil)
  • merchant (String, nil) (defaults to: nil)
  • min_price (Integer, nil) (defaults to: nil)
  • min_reviews_rating (Integer, nil) (defaults to: nil)
  • min_savings_percent (Integer, nil) (defaults to: nil)
  • offer_count (Integer, nil) (defaults to: nil)
  • properties (Hash, nil)
  • resources (Array<String>, nil) (defaults to: nil)
  • search_index (String, nil) (defaults to: nil)
  • sort_by (String, nil) (defaults to: nil)
  • title (String, nil) (defaults to: nil)

Returns:

See Also:


122
123
124
# File 'lib/vacuum/request.rb', line 122

def search_items(**params)
  request('SearchItems', params)
end

#use(*features) ⇒ self

Turn on HTTP features

Parameters:

  • features

Returns:

  • (self)

149
150
151
152
153
# File 'lib/vacuum/request.rb', line 149

%i[timeout via through headers use].each do |method_name|
  define_method(method_name) do |*args, &block|
    @client = client.send(method_name, *args, &block)
  end
end

#via(*proxy) ⇒ self

Make a request through an HTTP proxy

Parameters:

  • proxy (Array)

Returns:

  • (self)

Raises:

  • (HTTP::Request::Error)

    if HTTP proxy is invalid


149
150
151
152
153
# File 'lib/vacuum/request.rb', line 149

%i[timeout via through headers use].each do |method_name|
  define_method(method_name) do |*args, &block|
    @client = client.send(method_name, *args, &block)
  end
end