Class: Vacuum::Request

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

Overview

An Amazon Product Advertising API request.

Constant Summary

BadLocale =
Class.new(ArgumentError)
MissingTag =
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',
  'UK' => 'ecs.amazonaws.co.uk',
  'US' => 'ecs.amazonaws.com'
}.freeze

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Request) initialize(locale = nil)

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.



33
34
35
36
# File 'lib/vacuum/request.rb', line 33

def initialize(locale = nil)
  host = HOSTS[locale || 'US'] or raise BadLocale
  self.endpoint = "http://#{host}/onca/xml"
end

Instance Attribute Details

- (Object) tag

Get the String Associate Tag.

Raises a Missing Tag error if Associate Tag is missing.



53
54
55
# File 'lib/vacuum/request.rb', line 53

def tag
  @tag or raise MissingTag
end

Instance Method Details

- (Object) configure(credentials)

Configure the Amazon Product Advertising API request.

credentials - The Hash credentials of the API endpoint.

:key    - The String Amazon Web Services (AWS) key.
:secret - The String AWS secret.
:tag    - The String Associate Tag.

Returns nothing.



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

def configure(credentials)
  credentials.each { |key, val| self.send("#{key}=", val) }
end

- (Object) url(params)

Build a URL.

params - A Hash of Amazon Product Advertising query params.

Returns the built URL String.



65
66
67
68
69
70
71
72
# File 'lib/vacuum/request.rb', line 65

def url(params)
  opts = {
    :method => :get,
    :query  => params
  }

  [endpoint, build_options(opts).fetch(:query)].join('?')
end