class MWS::QueryString

Constants

DEFAULT_METHOD
DEFAULT_PARAMS
DEFAULT_PATH

Public Class Methods

new(args) click to toggle source
Calls superclass method
# File lib/mws/query_string.rb, line 15
def initialize(args)
  @key      = args[:key]
  @method   = args[:method] || DEFAULT_METHOD
  @endpoint = args[:endpoint]
  @path     = args[:path] || DEFAULT_PATH
  @params   = DEFAULT_PARAMS.merge(args[:params])

  @params["Timestamp"] = timestamp_string
  @params["Signature"] = signature_string # This substitution must be final substitution

  super(query_string)
end

Private Instance Methods

expanded_params() click to toggle source
# File lib/mws/query_string.rb, line 38
def expanded_params
  params = {}
  @params.each do |key, value|
    if Array === value
      value.each.with_index(1) do |v, idx|
        element_name = key.match(/([A-Z][a-z]+)List/)[1]
        new_key = [key, element_name, idx.to_s].join(".")
        params[new_key] = v
      end
    else
      params[key] = value
    end
  end
  params
end
query_string() click to toggle source
# File lib/mws/query_string.rb, line 30
def query_string
  sorted_params.each.map{|k, v| [k, PercentEncodedString.new(v)].join("=") }.join("&")
end
request_string() click to toggle source
# File lib/mws/query_string.rb, line 62
def request_string
  MWS::QueryString::RequestString.new(method: @method, endpoint: @endpoint, path: @path, params: expanded_params)
end
signature_string() click to toggle source
# File lib/mws/query_string.rb, line 58
def signature_string
  MWS::QueryString::Signature.new(request_string, @key)
end
sorted_params() click to toggle source
# File lib/mws/query_string.rb, line 34
def sorted_params
  expanded_params.sort_by{|k, _v| k }
end
timestamp_string() click to toggle source
# File lib/mws/query_string.rb, line 54
def timestamp_string
  (@params["Timestamp"].is_a?(Time) ? @params["Timestamp"] : Time.now).getutc.iso8601
end