Class: URI::HTTP

Inherits:
Object
  • Object
show all
Defined in:
lib/hub/speedy_stdlib.rb

Direct Known Subclasses

Hub::Context::GithubURL

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str) ⇒ HTTP

Returns a new instance of HTTP.

Raises:



62
63
64
65
66
67
68
69
# File 'lib/hub/speedy_stdlib.rb', line 62

def initialize(str)
  m = str.to_s.match(%r{^ ([\w-]+): // (?:([^/@]+)@)? ([^/?#]+) }x)
  raise InvalidURIError unless m
  _, self.scheme, self.userinfo, host = m.to_a
  self.host, self.port = host.split(':', 2)
  path, self.fragment = m.post_match.split('#', 2)
  self.path, self.query = path.to_s.split('?', 2)
end

Instance Attribute Details

#fragmentObject

Returns the value of attribute fragment.



58
59
60
# File 'lib/hub/speedy_stdlib.rb', line 58

def fragment
  @fragment
end

#hostObject Also known as: hostname

Returns the value of attribute host.



58
59
60
# File 'lib/hub/speedy_stdlib.rb', line 58

def host
  @host
end

#passwordObject

Returns the value of attribute password.



58
59
60
# File 'lib/hub/speedy_stdlib.rb', line 58

def password
  @password
end

#pathObject

Returns the value of attribute path.



58
59
60
# File 'lib/hub/speedy_stdlib.rb', line 58

def path
  @path
end

#portObject



88
89
90
# File 'lib/hub/speedy_stdlib.rb', line 88

def port
  (@port || (scheme == 'https' ? 443 : 80)).to_i
end

#queryObject

Returns the value of attribute query.



58
59
60
# File 'lib/hub/speedy_stdlib.rb', line 58

def query
  @query
end

#schemeObject

Returns the value of attribute scheme.



58
59
60
# File 'lib/hub/speedy_stdlib.rb', line 58

def scheme
  @scheme
end

#userObject

Returns the value of attribute user.



58
59
60
# File 'lib/hub/speedy_stdlib.rb', line 58

def user
  @user
end

Instance Method Details

#find_proxyObject



103
104
# File 'lib/hub/speedy_stdlib.rb', line 103

def find_proxy
end

#request_uriObject



82
83
84
85
86
# File 'lib/hub/speedy_stdlib.rb', line 82

def request_uri
  url = path
  url += "?#{query}" if query
  url
end

#to_sObject



71
72
73
74
75
76
77
78
79
80
# File 'lib/hub/speedy_stdlib.rb', line 71

def to_s
  url = "#{scheme}://"
  url << "#{userinfo}@" if user || password
  url << host
  url << ":#{@port}" if @port
  url << path
  url << "?#{query}" if query
  url << "##{fragment}" if fragment
  url
end

#userinfoObject



97
98
99
100
101
# File 'lib/hub/speedy_stdlib.rb', line 97

def userinfo
  if password then "#{user}:#{password}"
  elsif user then user
  end
end

#userinfo=(info) ⇒ Object



92
93
94
95
# File 'lib/hub/speedy_stdlib.rb', line 92

def userinfo=(info)
  self.user, self.password = info.to_s.split(':', 2)
  info
end