Class: Hash

Inherits:
Object show all
Defined in:
lib/amazon/mws/lib/extensions.rb,
lib/amazon/mws/lib/extensions.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_query_string(string) ⇒ Object



46
47
48
49
50
# File 'lib/amazon/mws/lib/extensions.rb', line 46

def self.from_query_string(string)
  query = string.split(/\?/)[-1]
  parts = query.split(/&|=/)
  Hash[*parts]
end

.keys_to_s(value) ⇒ Object

take keys of hash and transform those to a symbols



53
54
55
56
57
# File 'lib/amazon/mws/lib/extensions.rb', line 53

def self.keys_to_s(value)
  return value if not value.is_a?(Hash)
  hash = value.inject({}){|memo,(k,v)| memo[k.to_s] = Hash.keys_to_s(v); memo}
  return hash
end

Instance Method Details

#to_query_stringObject



72
73
74
# File 'lib/amazon/mws/lib/extensions.rb', line 72

def to_query_string
  self.map { |k,v| "%s=%s" % [URI.encode(k.to_s), URI.encode(v.to_s)] }.join('&') unless self.empty?
end