class Vacuum::Request

A request to the Amazon Product Advertising API

Attributes

client[R]

@return [HTTP::Client]

locale[R]

@return [Locale]

operation[R]

@return [Operation]

Public Class Methods

new(marketplace: :us, **args) click to toggle source

Creates a new request

@overload initialize(marketplace: :us, access_key:, secret_key:, partner_tag:, partner_type:)

@param [Symbol,String] marketplace
@param [String] access_key
@param [String] secret_key
@param [String] partner_tag
@param [String] partner_type
@raise [Locale::NotFound] if marketplace is not found
# File lib/vacuum/request.rb, line 30
def initialize(marketplace: :us, **args)
  @locale = Locale.new(marketplace, **args)
  @client = HTTP::Client.new
end

Public Instance Methods

get_browse_nodes(browse_node_ids:, **params) click to toggle source

Returns details about specified browse nodes

@see webservices.amazon.com/paapi5/documentation/getbrowsenodes.html @overload get_browse_nodes(browse_node_ids:, languages_of_preference: nil, marketplace: nil, partner_tag: nil, partner_type: nil, resources: nil)

@param [Array<String,Integer>,String,Integer] browse_node_ids
@param [Array<String>,nil] languages_of_preference
@param [String,nil] marketplace
@param [String,nil] partner_tag
@param [String,nil] partner_type
@param [Array<String>,nil] resources

@return [Response]

# 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(item_ids:, **params) click to toggle source

Returns the attributes of one or more items

@see webservices.amazon.com/paapi5/documentation/get-items.html @overload 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)

@param [String,nil] condition
@param [String,nil] currency_of_preference
@param [String,nil] item_id_type
@param [Array<String>,String] item_ids
@param [Array<String>,nil] languages_of_preference
@param [String,nil] marketplace
@param [String,nil] merchant
@param [Integer,nil] offer_count
@param [String,nil] partner_tag
@param [String,nil] partner_type
@param [Array<String>,nil] resources

@return [Response]

# 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(**params) click to toggle source

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

@see webservices.amazon.com/paapi5/documentation/get-variations.html @overload 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)

@param [String] asin
@param [String,nil] condition
@param [String,nil] currency_of_preference
@param [Array<String>,nil] languages_of_preference
@param [String,nil] marketplace
@param [String,nil] merchant
@param [Integer,nil] offer_count
@param [String,nil] partner_tag
@param [String,nil] partner_type
@param [Array<String>,nil] resources
@param [Integer,nil] variation_count
@param [Integer,nil] variation_page
@return [Response]
# File lib/vacuum/request.rb, line 90
def get_variations(**params)
  request('GetVariations', params)
end
persistent(timeout: 5) click to toggle source

Flags as persistent

@param [Integer] timeout @return [self]

# 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(**params) click to toggle source

Searches for items on Amazon based on a search query

@see webservices.amazon.com/paapi5/documentation/search-items.html @overload 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)

@param [String,nil] actor
@param [String,nil] artist
@param [String,nil] availability
@param [String,nil] brand
@param [Integer,nil] browse_node_id
@param [String,nil] condition
@param [String,nil] currency_of_preference
@param [Array<String>,nil] delivery_flags
@param [Integer,nil] item_count
@param [Integer,nil] item_page
@param [String,nil] keywords
@param [Array<String>,nil] languages_of_preference
@param [Integer,nil] max_price
@param [String,nil] merchant
@param [Integer,nil] min_price
@param [Integer,nil] min_reviews_rating
@param [Integer,nil] min_savings_percent
@param [Integer,nil] offer_count
@param [Hash,nil] properties
@param [Array<String>,nil] resources
@param [String,nil] search_index
@param [String,nil] sort_by
@param [String,nil] title

@return [Response]

# File lib/vacuum/request.rb, line 122
def search_items(**params)
  request('SearchItems', params)
end

Private Instance Methods

request(operation_name, params) click to toggle source
# File lib/vacuum/request.rb, line 164
def request(operation_name, params)
  validate_keywords(params)
  @operation = Operation.new(operation_name, params: params, locale: locale)
  response = client.headers(operation.headers)
                   .post(operation.url, body: operation.body)

  Response.new(response)
end
validate_keywords(params) click to toggle source
# File lib/vacuum/request.rb, line 157
def validate_keywords(params)
  return unless params[:keywords]
  return if params[:keywords].is_a?(String)

  raise ArgumentError, ':keyword argument expects a String'
end