Module: Kameleoon::Network::UriHelper

Defined in:
lib/kameleoon/network/uri_helper.rb

Overview

UriHelper contains functions which helps working with URIs.

Class Method Summary collapse

Class Method Details

.encode_query(params) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/kameleoon/network/uri_helper.rb', line 23

def self.encode_query(params)
  params.delete_if { |_k, v| v.nil? || (v == '') }
  encoded = URI.encode_www_form(params)
  encoded.gsub!(/%21|%27|%28|%29|%7E|\+/,
                '%21' => '!',
                '%27' => "'",
                '%28' => '(',
                '%29' => ')',
                '%7E' => '~',
                '+' => '%20')
  encoded
end

.encode_uri(uri) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/kameleoon/network/uri_helper.rb', line 11

def self.encode_uri(uri)
  encoded = CGI.escape(uri)
  encoded.gsub!(/%21|%27|%28|%29|%2A|\+/,
                '%21' => '!',
                '%27' => "'",
                '%28' => '(',
                '%29' => ')',
                '%2A' => '*',
                '+' => '%20')
  encoded
end