Class: Amazon::MWS::Authentication::QueryString

Inherits:
String
  • Object
show all
Defined in:
lib/amazon/mws/authentication/query_string.rb

Instance Method Summary collapse

Methods inherited from String

#camelize

Constructor Details

#initialize(params = {}) ⇒ QueryString

Returns a new instance of QueryString.



4
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/amazon/mws/authentication/query_string.rb', line 4

def initialize(params = {})
  query_params = {
    'AWSAccessKeyId'   => params[:access_key],
    'SignatureMethod'  => Signature::METHOD,
    'SignatureVersion' => Signature::VERSION,
    'Timestamp'        => Time.now.iso8601
  }
  
  if params[:path].include? 'Orders'
    query_params['SellerId'] = params[:merchant_id]
    query_params['Version'] = Amazon::MWS::Authentication::ORDERS_VERSION
  elsif params[:path].include? 'Products'
    query_params['SellerId'] = params[:merchant_id]
    query_params['Version'] = Amazon::MWS::Authentication::PRODUCTS_VERSION
  else
    query_params['Merchant'] = params[:merchant_id]
    query_params['Version'] = Amazon::MWS::Authentication::VERSION       
  end

  # Add any params that are passed in via uri before calculating the signature
  query_params = query_params.merge(params[:query_params] || {})
  # Calculate the signature
  query_params['Signature'] = Signature.new(query_params, params)

  self << formatted_querystring(query_params)
end

Instance Method Details

#formatted_querystring(query_params) ⇒ Object



31
32
33
# File 'lib/amazon/mws/authentication/query_string.rb', line 31

def formatted_querystring(query_params)
  query_params.collect { |key, value| [CGI.escape(key.to_s), CGI.escape(value.to_s)].join('=') }.join('&') # order doesn't matter for the actual request
end