Class: Squake::Util

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/squake/util.rb

Class Method Summary collapse

Class Method Details

.encode_parameters(params) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/squake/util.rb', line 13

def self.encode_parameters(params)
  params.map do |k, v|
    case v
    when Array
      v.map { |e| "#{url_encode(k.to_s)}[]=#{url_encode(e.to_s)}" }.join('&')
    else
      "#{url_encode(k.to_s)}=#{url_encode(v.to_s)}" unless v.nil?
    end
  end.join('&')
end

.url_encode(key) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/squake/util.rb', line 28

def self.url_encode(key)
  CGI.escape(key.to_s).
    # Don't use strict form encoding by changing the square bracket control
    # characters back to their literals. This is fine by the server, and
    # makes these parameter strings easier to read.
    gsub('%5B', '[').gsub('%5D', ']')
end