Class: Mws::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/mws/query.rb

Instance Method Summary collapse

Constructor Details

#initialize(overrides) ⇒ Query

Returns a new instance of Query.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/mws/query.rb', line 5

def initialize(overrides)
  options = {
    signature_method: 'HmacSHA256',
    signature_version: '2',
    timestamp: Time.now.iso8601
  }.merge overrides

  options[:aws_access_key_id] ||= options.delete :access
  options[:seller_id] ||= options.delete(:merchant) || options.delete(:seller)
  options[:marketplace_id] ||= options.delete(:markets) || []
  list_pattern = options.delete(:list_pattern) || '%{key}List.%{ext}.%<index>d'
  
  @params = Hash[options.inject({}) do | params, entry |
    key = normalize_key entry.first
    if entry.last.respond_to? :each_with_index
      entry.last.each_with_index do | value, index |
        param_key = list_pattern % { key: key, ext: entry.first.to_s.split('_').last.capitalize, index: index + 1 }
        params[param_key] = normalize_val value
      end
    else
      params[key] = normalize_val entry.last
    end
    params
  end.sort]
end

Instance Method Details

#to_sObject



31
32
33
# File 'lib/mws/query.rb', line 31

def to_s
  @params.map { |it| it.join '=' }.join '&'
end