Sha256: e9e4b65b6409fcaf20ee366d1b5b2a1859d9f27d0e0598b6fa5bf4928705e396
Contents?: true
Size: 1.12 KB
Versions: 45
Compression:
Stored size: 1.12 KB
Contents
module Signature # Query string encoding extracted with thanks from em-http-request module QueryEncoder class << self # URL encodes query parameters: # single k=v, or a URL encoded array, if v is an array of values 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 # Like encode_param, but doesn't url escape keys or values def encode_param_without_escaping(k, v) if v.is_a?(Array) v.map { |e| k + "[]=" + e }.join("&") else "#{k}=#{v}" end end private def escape(s) if defined?(EscapeUtils) EscapeUtils.escape_url(s.to_s) else s.to_s.gsub(/([^a-zA-Z0-9_.-]+)/n) { '%'+$1.unpack('H2'*bytesize($1)).join('%').upcase } end end if ''.respond_to?(:bytesize) def bytesize(string) string.bytesize end else def bytesize(string) string.size end end end end end
Version data entries
45 entries across 45 versions & 3 rubygems