Class: HideMyAss::Proxy

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

Overview

Interface for the attributes of each proxy. Such attributes include the ip, port and protocol.

Examples:

Get the proxy’s ip address.

proxy.ip
# => '178.22.148.122'

Get the proxy’s port.

proxy.port
# => 3129

Get the proxy’s protocol.

proxy.protocol
# => 'HTTPS'

Get the hosted country.

proxy.country
# => 'FRANCE'

Get the complete url.

proxy.url
# => 'https://178.22.148.122:3129'

Instance Method Summary collapse

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.

Parameters:

  • row (Nokogiri::XML)

    Pre-parsed row element.



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.

Returns:

  • (Boolean)


157
158
159
# File 'lib/hidemyass/proxy.rb', line 157

def anonym?
  anonymity.start_with? 'high'
end

#anonymityString

The level of anonymity in downcase letters. (low, medium, high, …)

Returns:

  • (String)


108
109
110
# File 'lib/hidemyass/proxy.rb', line 108

def anonymity
  @anonymity ||= @row.at_xpath('td[8]').text.strip.downcase
end

#connection_timeInt

The average connection time in milliseconds.

Returns:

  • (Int)


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

#countryString

The country where the proxy is hosted in downcase letters.

Returns:

  • (String)


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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


136
137
138
# File 'lib/hidemyass/proxy.rb', line 136

def https?
  protocol == 'https'
end

#inspectString

:nocov: Custom inspect method.

> ‘<HideMyAss::Proxy 123.57.52.171:80>’

Examples:

inspect

Returns:

  • (String)


176
177
178
# File 'lib/hidemyass/proxy.rb', line 176

def inspect
  "<#{self.class.name} #{url}>"
end

#ipString

The IP of the proxy server.

Returns:

  • (String)


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_updatedInt Also known as: last_test

Time in seconds when the last ping was made.

Returns:

  • (Int)


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

#portInt

The port for the proxy.

Returns:

  • (Int)


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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


143
144
145
# File 'lib/hidemyass/proxy.rb', line 143

def socks?
  protocol.start_with? 'socks'
end

#speedInt Also known as: response_time

The average response time in milliseconds.

Returns:

  • (Int)


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.

Returns:

  • (Boolean)


150
151
152
# File 'lib/hidemyass/proxy.rb', line 150

def ssl?
  https? || socks?
end

#typeString Also known as: protocol

The network protocol in in downcase letters. (https or http or socks)

Returns:

  • (String)


98
99
100
# File 'lib/hidemyass/proxy.rb', line 98

def type
  @type ||= @row.at_xpath('td[7]').text.strip.downcase[0..4]
end

#urlString

The complete URL of that proxy server.

Returns:

  • (String)


115
116
117
# File 'lib/hidemyass/proxy.rb', line 115

def url
  "#{protocol}://#{ip}:#{port}"
end

#valid?Boolean

If the IP is valid.

Returns:

  • (Boolean)


122
123
124
# File 'lib/hidemyass/proxy.rb', line 122

def valid?
  ip.split('.').reject(&:empty?).count == 4
end