Class: ProxyFetcher::Proxy
- Inherits:
-
Object
- Object
- ProxyFetcher::Proxy
- Defined in:
- lib/proxy_fetcher/proxy.rb
Overview
Proxy object
Constant Summary collapse
- TYPES =
Proxy types
[ HTTP = "HTTP", HTTPS = "HTTPS", SOCKS4 = "SOCKS4", SOCKS5 = "SOCKS5" ].freeze
Instance Attribute Summary collapse
-
#addr ⇒ String
Address (IP or domain).
-
#anonymity ⇒ String
Anonymity level (high, elite, transparent, etc).
-
#country ⇒ String
Country or country code.
-
#port ⇒ Integer
Port.
-
#response_time ⇒ Integer
Response time (value and measurements depends on the provider).
-
#type ⇒ String
Type (SOCKS, HTTP(S)).
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#connectable? ⇒ Boolean
(also: #valid?)
Checks if proxy object is connectable (can be used as a proxy for HTTP requests).
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(attributes = {}) ⇒ Proxy
constructor
Initialize new Proxy.
-
#proxy_type ⇒ Boolean
Proxy type predicates (#socks4?, #https?).
-
#ssl? ⇒ Boolean
Returns true if proxy is secure (works through https, socks4 or socks5).
-
#uri ⇒ URI::Generic
Returns
URI::Generic
object with host and port values of the proxy. -
#url(scheme: false) ⇒ String
Returns
String
object with addr:port values of the proxy.
Constructor Details
#initialize(attributes = {}) ⇒ Proxy
Initialize new Proxy
65 66 67 68 69 |
# File 'lib/proxy_fetcher/proxy.rb', line 65 def initialize(attributes = {}) attributes.each do |attr, value| public_send("#{attr}=", value) end end |
Instance Attribute Details
#addr ⇒ String
Returns address (IP or domain).
8 9 10 |
# File 'lib/proxy_fetcher/proxy.rb', line 8 def addr @addr end |
#anonymity ⇒ String
Returns anonymity level (high, elite, transparent, etc).
28 29 30 |
# File 'lib/proxy_fetcher/proxy.rb', line 28 def anonymity @anonymity end |
#country ⇒ String
Returns country or country code.
20 21 22 |
# File 'lib/proxy_fetcher/proxy.rb', line 20 def country @country end |
#port ⇒ Integer
Returns port.
12 13 14 |
# File 'lib/proxy_fetcher/proxy.rb', line 12 def port @port end |
#response_time ⇒ Integer
Returns response time (value and measurements depends on the provider).
24 25 26 |
# File 'lib/proxy_fetcher/proxy.rb', line 24 def response_time @response_time end |
#type ⇒ String
Returns type (SOCKS, HTTP(S)).
16 17 18 |
# File 'lib/proxy_fetcher/proxy.rb', line 16 def type @type end |
Instance Method Details
#==(other) ⇒ Object
108 109 110 |
# File 'lib/proxy_fetcher/proxy.rb', line 108 def ==(other) other.is_a?(Proxy) && addr == other.addr && port == other.port end |
#connectable? ⇒ Boolean Also known as: valid?
Checks if proxy object is connectable (can be used as a proxy for HTTP requests).
77 78 79 |
# File 'lib/proxy_fetcher/proxy.rb', line 77 def connectable? ProxyFetcher.config.proxy_validator.connectable?(addr, port) end |
#eql?(other) ⇒ Boolean
112 113 114 |
# File 'lib/proxy_fetcher/proxy.rb', line 112 def eql?(other) hash.eql?(other.hash) end |
#hash ⇒ Object
116 117 118 |
# File 'lib/proxy_fetcher/proxy.rb', line 116 def hash [addr.hash, port.hash].hash end |
#proxy_type ⇒ Boolean
Proxy type predicates (#socks4?, #https?)
43 44 45 46 47 |
# File 'lib/proxy_fetcher/proxy.rb', line 43 TYPES.each do |proxy_type| define_method "#{proxy_type.downcase}?" do !type.nil? && type.upcase.include?(proxy_type) end end |
#ssl? ⇒ Boolean
Returns true if proxy is secure (works through https, socks4 or socks5).
54 55 56 |
# File 'lib/proxy_fetcher/proxy.rb', line 54 def ssl? https? || socks4? || socks5? end |
#uri ⇒ URI::Generic
Returns URI::Generic
object with host and port values of the proxy.
88 89 90 |
# File 'lib/proxy_fetcher/proxy.rb', line 88 def uri URI::Generic.build(host: addr, port: port) end |
#url(scheme: false) ⇒ String
Returns String
object with addr:port values of the proxy.
100 101 102 103 104 105 106 |
# File 'lib/proxy_fetcher/proxy.rb', line 100 def url(scheme: false) if scheme URI::Generic.build(scheme: type, host: addr, port: port).to_s else URI::Generic.build(host: addr, port: port).to_s end end |