Class: Vacuum::Request
Overview
An Amazon Product Advertising API request.
Constant Summary collapse
- BadLocale =
Class.new(ArgumentError)
- HOSTS =
A list of Amazon Product Advertising API hosts.
{ 'CA' => 'ecs.amazonaws.ca', 'CN' => 'webservices.amazon.cn', 'DE' => 'ecs.amazonaws.de', 'ES' => 'webservices.amazon.es', 'FR' => 'ecs.amazonaws.fr', 'IT' => 'webservices.amazon.it', 'JP' => 'ecs.amazonaws.jp', 'GB' => 'ecs.amazonaws.co.uk', 'US' => 'ecs.amazonaws.com' }.freeze
Instance Attribute Summary collapse
-
#associate_tag ⇒ Object
(also: #tag)
Get/Sets the String Associate Tag.
Instance Method Summary collapse
-
#configure(credentials) ⇒ Object
Configure the Amazon Product Advertising API request.
-
#initialize(locale = nil) ⇒ Request
constructor
Create a new request for given locale.
-
#url(params) ⇒ Object
Build a URL.
Constructor Details
#initialize(locale = nil) ⇒ Request
Create a new request for given locale.
locale - The String Product Advertising API locale (default: US).
Raises a Bad Locale error if locale is not valid.
32 33 34 35 36 37 38 39 40 |
# File 'lib/vacuum/request.rb', line 32 def initialize(locale = nil) if locale == 'UK' warn '[DEPRECATION] Use GB instead of UK' locale = 'GB' end host = HOSTS[locale || 'US'] or raise BadLocale self.endpoint = "http://#{host}/onca/xml" end |
Instance Attribute Details
#associate_tag ⇒ Object Also known as: tag
Get/Sets the String Associate Tag.
57 58 59 |
# File 'lib/vacuum/request.rb', line 57 def associate_tag @associate_tag end |
Instance Method Details
#configure(credentials) ⇒ Object
Configure the Amazon Product Advertising API request.
credentials - The Hash credentials of the API endpoint.
:aws_access_key_id - The String Amazon Web Services
(AWS) key.
:aws_secret_access_key - The String AWS secret.
:associate_tag - The String Associate Tag.
Returns self.
51 52 53 54 |
# File 'lib/vacuum/request.rb', line 51 def configure(credentials) credentials.each { |key, val| self.send("#{key}=", val) } self end |
#url(params) ⇒ Object
Build a URL.
params - A Hash of Amazon Product Advertising query params.
Returns the built URL String.
67 68 69 70 71 72 73 74 |
# File 'lib/vacuum/request.rb', line 67 def url(params) opts = { method: :get, query: params } [endpoint, (opts).fetch(:query)].join('?') end |