Module: HTTParty::HashConversions

Defined in:
lib/alula/monkey_patches.rb

Class Method Summary collapse

Class Method Details

.normalize_param(key, value) ⇒ String

Returns This key value pair as a param.

Examples:

normalize_param(:name, “Bob Jones”) #=> “name=Bob%20Jones&”

Parameters:

  • key (Object)

    The key for the param.

  • value (Object)

    The value for the param.

Returns:

  • (String)

    This key value pair as a param



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/alula/monkey_patches.rb', line 9

def self.normalize_param(key, value)
  normalized_keys = normalize_keys(key, value)

  normalized_keys.flatten.each_slice(2).inject('') do |string, (k, v)|
    # TODO: TJ - Our API needs nil params to be blank, aka '&someParam&' 
    #       and not '&someParam=', otherwise we take that as an empty string.
    #       Monkey patch to get around this problem.
    if v.nil?
      string + "#{ERB::Util.url_encode(k)}&"
    else
      string + "#{ERB::Util.url_encode(k)}=#{ERB::Util.url_encode(v.to_s)}&"
    end
  end
end