Class: HideMyAss::Proxy
- Inherits:
-
Object
- Object
- HideMyAss::Proxy
- Defined in:
- lib/hidemyass/proxy.rb
Overview
Interface for the attributes of each proxy. Such attributes include the ip, port and protocol.
Instance Method Summary collapse
-
#anonym? ⇒ Boolean
If the proxy’s anonymity is high or even higher.
-
#anonymity ⇒ String
The level of anonymity in downcase letters.
-
#connection_time ⇒ Int
The average connection time in milliseconds.
-
#country ⇒ String
The country where the proxy is hosted in downcase letters.
-
#http? ⇒ Boolean
If the proxy’s network protocol is HTTP.
-
#https? ⇒ Boolean
If the proxy’s network protocol is HTTPS.
-
#initialize(row) ⇒ HideMyAss::Proxy
constructor
Initializes the proxy instance by passing a single row of the fetched result list.
-
#inspect ⇒ String
:nocov: Custom inspect method.
-
#ip ⇒ String
The IP of the proxy server.
-
#last_updated ⇒ Int
(also: #last_test)
Time in seconds when the last ping was made.
-
#port ⇒ Int
The port for the proxy.
-
#secure? ⇒ Boolean
If the proxy’s anonymity is at least high and protocol is encrypted.
-
#socks? ⇒ Boolean
If the proxy’s network protocol is SOCKS.
-
#speed ⇒ Int
(also: #response_time)
The average response time in milliseconds.
-
#ssl? ⇒ Boolean
If the proxy supports SSL encryption.
-
#type ⇒ String
(also: #protocol)
The network protocol in in downcase letters.
-
#url ⇒ String
The complete URL of that proxy server.
-
#valid? ⇒ Boolean
If the IP is valid.
Constructor Details
#initialize(row) ⇒ HideMyAss::Proxy
Initializes the proxy instance by passing a single row of the fetched result list. All attribute readers are lazy implemented.
32 33 34 |
# File 'lib/hidemyass/proxy.rb', line 32 def initialize(row) @row = row end |
Instance Method Details
#anonym? ⇒ Boolean
If the proxy’s anonymity is high or even higher.
157 158 159 |
# File 'lib/hidemyass/proxy.rb', line 157 def anonym? anonymity.start_with? 'high' end |
#anonymity ⇒ String
The level of anonymity in downcase letters. (low, medium, high, …)
108 109 110 |
# File 'lib/hidemyass/proxy.rb', line 108 def anonymity @anonymity ||= @row.at_xpath('td[8]').text.strip.downcase end |
#connection_time ⇒ Int
The average connection time in milliseconds.
90 91 92 |
# File 'lib/hidemyass/proxy.rb', line 90 def connection_time @connection_time ||= @row.at_xpath('td[6]/div')[:value].to_i end |
#country ⇒ String
The country where the proxy is hosted in downcase letters.
74 75 76 |
# File 'lib/hidemyass/proxy.rb', line 74 def country @country ||= @row.at_xpath('td[4]').text.strip.downcase end |
#http? ⇒ Boolean
If the proxy’s network protocol is HTTP.
129 130 131 |
# File 'lib/hidemyass/proxy.rb', line 129 def http? protocol == 'http' end |
#https? ⇒ Boolean
If the proxy’s network protocol is HTTPS.
136 137 138 |
# File 'lib/hidemyass/proxy.rb', line 136 def https? protocol == 'https' end |
#inspect ⇒ String
:nocov: Custom inspect method.
> ‘<HideMyAss::Proxy 123.57.52.171:80>’
176 177 178 |
# File 'lib/hidemyass/proxy.rb', line 176 def inspect "<#{self.class.name} #{url}>" end |
#ip ⇒ String
The IP of the proxy server.
57 58 59 60 61 62 |
# File 'lib/hidemyass/proxy.rb', line 57 def ip @ip ||= @row.at_xpath('td[2]/span').children .select { |el| ip_block? el } .map! { |el| el.text.strip } .join('') end |
#last_updated ⇒ Int Also known as: last_test
Time in seconds when the last ping was made.
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/hidemyass/proxy.rb', line 39 def last_updated @last_updated ||= begin @row.at_xpath('td[1]').text.strip.split(' ').map do |it| case it when /sec/ then it.scan(/\d+/)[0].to_i when /min/ then it.scan(/\d+/)[0].to_i * 60 when /h/ then it.scan(/\d+/)[0].to_i * 3_600 when /d/ then it.scan(/\d+/)[0].to_i * 86_400 end end.reduce(&:+) end end |
#port ⇒ Int
The port for the proxy.
67 68 69 |
# File 'lib/hidemyass/proxy.rb', line 67 def port @port ||= @row.at_xpath('td[3]').text.strip.to_i end |
#secure? ⇒ Boolean
If the proxy’s anonymity is at least high and protocol is encrypted.
164 165 166 |
# File 'lib/hidemyass/proxy.rb', line 164 def secure? anonym? && ssl? end |
#socks? ⇒ Boolean
If the proxy’s network protocol is SOCKS.
143 144 145 |
# File 'lib/hidemyass/proxy.rb', line 143 def socks? protocol.start_with? 'socks' end |
#speed ⇒ Int Also known as: response_time
The average response time in milliseconds.
81 82 83 |
# File 'lib/hidemyass/proxy.rb', line 81 def speed @speed ||= @row.at_xpath('td[5]/div')[:value].to_i end |
#ssl? ⇒ Boolean
If the proxy supports SSL encryption.
150 151 152 |
# File 'lib/hidemyass/proxy.rb', line 150 def ssl? https? || socks? end |
#type ⇒ String Also known as: protocol
The network protocol in in downcase letters. (https or http or socks)
98 99 100 |
# File 'lib/hidemyass/proxy.rb', line 98 def type @type ||= @row.at_xpath('td[7]').text.strip.downcase[0..4] end |
#url ⇒ String
The complete URL of that proxy server.
115 116 117 |
# File 'lib/hidemyass/proxy.rb', line 115 def url "#{protocol}://#{ip}:#{port}" end |
#valid? ⇒ Boolean
If the IP is valid.
122 123 124 |
# File 'lib/hidemyass/proxy.rb', line 122 def valid? ip.split('.').reject(&:empty?).count == 4 end |