Module: Emporium::Services::Utilities

Included in:
Amazon, Google
Defined in:
lib/emporium/services/utilities.rb

Instance Method Summary collapse

Instance Method Details

#encode(value) ⇒ Object



24
25
26
# File 'lib/emporium/services/utilities.rb', line 24

def encode(value)
  CGI.escape(value)
end

#hash_from_json(json) ⇒ Object



14
15
16
# File 'lib/emporium/services/utilities.rb', line 14

def hash_from_json(json)
  JSON.parse(json)
end

#hash_from_xml(xml) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/emporium/services/utilities.rb', line 4

def hash_from_xml(xml)
  # Only the first level elements for now

  result_hash = {}
  xml.children.each do |value|
    result_hash[value.name.downcase.to_sym] = value.content
  end
  result_hash
end

#query(hash) ⇒ Object



18
19
20
21
22
# File 'lib/emporium/services/utilities.rb', line 18

def query(hash)
  hash.sort.collect { 
    |k, v| [encode(k), encode(v.to_s)].join("=") 
  }.join("&")
end