Class: ProxyFetcher::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/proxy_fetcher/proxy.rb

Constant Summary collapse

TYPES =
[
  HTTP = 'HTTP'.freeze,
  HTTPS = 'HTTPS'.freeze,
  SOCKS4 = 'SOCKS4'.freeze,
  SOCKS5 = 'SOCKS5'.freeze
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Proxy

Returns a new instance of Proxy.



22
23
24
25
26
# File 'lib/proxy_fetcher/proxy.rb', line 22

def initialize(attributes = {})
  attributes.each do |attr, value|
    public_send("#{attr}=", value)
  end
end

Instance Attribute Details

#addrObject

Returns the value of attribute addr.



3
4
5
# File 'lib/proxy_fetcher/proxy.rb', line 3

def addr
  @addr
end

#anonymityObject

Returns the value of attribute anonymity.



3
4
5
# File 'lib/proxy_fetcher/proxy.rb', line 3

def anonymity
  @anonymity
end

#countryObject

Returns the value of attribute country.



3
4
5
# File 'lib/proxy_fetcher/proxy.rb', line 3

def country
  @country
end

#portObject

Returns the value of attribute port.



3
4
5
# File 'lib/proxy_fetcher/proxy.rb', line 3

def port
  @port
end

#response_timeObject

Returns the value of attribute response_time.



3
4
5
# File 'lib/proxy_fetcher/proxy.rb', line 3

def response_time
  @response_time
end

#typeObject

Returns the value of attribute type.



3
4
5
# File 'lib/proxy_fetcher/proxy.rb', line 3

def type
  @type
end

Instance Method Details

#connectable?Boolean Also known as: valid?

Returns:

  • (Boolean)


28
29
30
# File 'lib/proxy_fetcher/proxy.rb', line 28

def connectable?
  ProxyFetcher.config.proxy_validator.connectable?(addr, port)
end

#ssl?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/proxy_fetcher/proxy.rb', line 18

def ssl?
  https? || socks4? || socks5?
end

#uriObject



34
35
36
# File 'lib/proxy_fetcher/proxy.rb', line 34

def uri
  URI::Generic.build(host: addr, port: port)
end

#urlObject



38
39
40
# File 'lib/proxy_fetcher/proxy.rb', line 38

def url
  "#{addr}:#{port}"
end