Module: EZPaypal::Helper

Defined in:
lib/core/helper.rb

Class Method Summary collapse

Class Method Details

.ConvertHashToQueryString(hash) ⇒ Object



29
30
31
# File 'lib/core/helper.rb', line 29

def self.ConvertHashToQueryString (hash)
  hash.map { |k, v| CGI::escape(k.to_s)+"="+CGI::escape(v.to_s) }.join("&")
end

.ConvertParamToHash(object) ⇒ Hash

Helper method to convert query string to hash also convert hash to encoded hash

Parameters:

  • object (String / Hash)

    to be converted or encoded

Returns:

  • (Hash)

    converted string or encoded hash



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/core/helper.rb', line 10

def self.ConvertParamToHash (object)
  hash_obj = HashWithIndifferentAccess.new()
  if (object.class.to_s == "String")
    object.split("&").each do |e|
      key = CGI::unescape(e.split("=")[0])
      value = CGI::unescape(e.split("=")[1])
      hash_obj.merge!(key => value)
    end
  else
    object.each do |key, value|
      key = CGI::unescape(key)
      value = CGI::unescape(value)
      hash_obj.merge!(key.upcase => value)
    end
  end

  return hash_obj
end