Module: Xignature::QueryEncoder

Included in:
Request
Defined in:
lib/xignature/query_encoder.rb

Overview

Query string encoding extracted with thanks from em-http-request

Class Method Summary collapse

Class Method Details

.encode_param(k, v) ⇒ Object

URL encodes query parameters: single k=v, or a URL encoded array, if v is an array of values



7
8
9
10
11
12
13
# File 'lib/xignature/query_encoder.rb', line 7

def encode_param(k, v)
  if v.is_a?(Array)
    v.map { |e| escape(k) + "[]=" + escape(e) }.join("&")
  else
    escape(k) + "=" + escape(v)
  end
end

.encode_param_without_escaping(k, v) ⇒ Object

Like encode_param, but doesn’t url escape keys or values



16
17
18
19
20
21
22
# File 'lib/xignature/query_encoder.rb', line 16

def encode_param_without_escaping(k, v)
  if v.is_a?(Array)
    v.map { |e| k + "[]=" + e }.join("&")
  else
    "#{k}=#{v}"
  end
end