Module: URI

Defined in:
lib/arctic/vendor/uri.rb

Class Method Summary collapse

Class Method Details

.params_hash(uri) ⇒ Object

Extracts a ruby hash from the URI query string



11
12
13
# File 'lib/arctic/vendor/uri.rb', line 11

def self.params_hash(uri)
  Hash[CGI.parse(uri.query).collect { |k, v| [k, v.join('')] }]
end

.replace_params(url, new_params) ⇒ Object

Merges the ‘new_params` with the existing query parameters from the `url`



3
4
5
6
7
8
# File 'lib/arctic/vendor/uri.rb', line 3

def self.replace_params(url, new_params)
  uri = parse url
  params = params_hash(uri).merge new_params
  new_url = "#{uri.scheme}://#{uri.host}#{uri.path}?#{new_params.to_query}##{uri.fragment}"
  parse new_url
end