Module: Patron::Util

Extended by:
Util
Included in:
Util
Defined in:
lib/patron/util.rb

Instance Method Summary collapse

Instance Method Details

#build_query_pairs_from_hash(hash, escape_values = false) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/patron/util.rb', line 5

def build_query_pairs_from_hash(hash, escape_values=false)
  pairs = []
  recursive = Proc.new do |h, prefix|
    h.each_pair do |k,v|
      key = prefix == '' ? k : "#{prefix}[#{k}]"
      v = Patron::Session.escape(v.to_s) if escape_values
      v.is_a?(Hash) ? recursive.call(v, key) : pairs << "#{key}=#{v}"
    end
  end
  recursive.call(hash, '')
  pairs
end

#build_query_string_from_hash(hash, escape_values = false) ⇒ Object



18
19
20
# File 'lib/patron/util.rb', line 18

def build_query_string_from_hash(hash, escape_values=false)
  build_query_pairs_from_hash(hash, escape_values).join('&')
end