Module: WebStub::URI

Defined in:
lib/webstub/uri.rb

Class Method Summary collapse

Class Method Details

.decode_www_form(str) ⇒ Object



3
4
5
6
7
8
9
10
# File 'lib/webstub/uri.rb', line 3

def self.decode_www_form(str)
  str.split("&").inject({}) do |hash, component|
    key, value = component.split("=", 2)
    hash[decode_www_form_component(key)] = decode_www_form_component(value)

    hash
  end
end

.decode_www_form_component(str) ⇒ Object



12
13
14
# File 'lib/webstub/uri.rb', line 12

def self.decode_www_form_component(str)
  str.gsub("+", " ").stringByReplacingPercentEscapesUsingEncoding(NSUTF8StringEncoding)
end

.split(str) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/webstub/uri.rb', line 16

def self.split(str)
  url = NSURL.URLWithString(str)

  scheme = url.scheme
  user = url.user
  password = url.password
  hostname = url.host
  port = url.port
  path = url.path
  query = url.query
  fragment = url.fragment

   = nil
  if user || password
     = "#{user}:#{password}"
  end

  [scheme, , hostname, port, path, query, fragment]
end