Class: ProxyRb::HttpProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/proxy_rb/http_proxy.rb

Overview

Represent proxy

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parser) ⇒ HttpProxy

Returns a new instance of HttpProxy.



13
14
15
16
# File 'lib/proxy_rb/http_proxy.rb', line 13

def initialize(parser)
  @url         = parser.proxy_url
  @credentials = parser.credentials
end

Instance Attribute Details

#credentialsObject (readonly)

Returns the value of attribute credentials.



11
12
13
# File 'lib/proxy_rb/http_proxy.rb', line 11

def credentials
  @credentials
end

#urlObject (readonly)

Returns the value of attribute url.



11
12
13
# File 'lib/proxy_rb/http_proxy.rb', line 11

def url
  @url
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/proxy_rb/http_proxy.rb', line 34

def empty?
  host.nil? || host.empty?
end

#full_urlProxyUrl

Return proxy as full url

Returns:



50
51
52
# File 'lib/proxy_rb/http_proxy.rb', line 50

def full_url
  ProxyUrl.build url.to_hash.merge(credentials.to_hash)
end

#hostObject



18
19
20
# File 'lib/proxy_rb/http_proxy.rb', line 18

def host
  url.host
end

#passwordObject



30
31
32
# File 'lib/proxy_rb/http_proxy.rb', line 30

def password
  credentials.password
end

#portObject



22
23
24
# File 'lib/proxy_rb/http_proxy.rb', line 22

def port
  url.port
end

#to_refSymbol

Convert to symbol to reference the proxy

Returns:

  • (Symbol)

    <host>_<port>_<credentials>



42
43
44
# File 'lib/proxy_rb/http_proxy.rb', line 42

def to_ref
  Shellwords.escape(*[host, port, user].compact.join('_')).to_sym
end

#userObject



26
27
28
# File 'lib/proxy_rb/http_proxy.rb', line 26

def user
  credentials.user_name
end