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)


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

def anonym?
  anonymity.start_with? 'high'
end

#anonymityString

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

Returns:

  • (String)


80
81
82
# File 'lib/hidemyass/proxy.rb', line 80

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

#countryString

The country where the proxy is hosted in downcase letters.

Returns:

  • (String)


53
54
55
56
# File 'lib/hidemyass/proxy.rb', line 53

def country
  @country ||= @row.at_xpath('td[3]/div/text()')
                   .text.strip.downcase!.scan(/[[:word:]]+$/).last
end

#http?Boolean

If the proxy’s network protocol is HTTP.

Returns:

  • (Boolean)


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

def http?
  protocol == 'http'
end

#https?Boolean

If the proxy’s network protocol is HTTPS.

Returns:

  • (Boolean)


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

def https?
  protocol == 'https'
end

#inspectString

Custom inspect method.

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

:nocov:

Examples:

inspect

Returns:

  • (String)


155
156
157
# File 'lib/hidemyass/proxy.rb', line 155

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

#ipString

The IP of the proxy server.

Returns:

  • (String)


39
40
41
# File 'lib/hidemyass/proxy.rb', line 39

def ip
  @ip ||= @row.at_xpath('td[1]/text()').text.strip
end

#last_checkInt

Time in minutes when its been last checked.

Returns:

  • (Int)


87
88
89
# File 'lib/hidemyass/proxy.rb', line 87

def last_check
  @last_check ||= @row.at_xpath('td[7]/text()').text.scan(/^\d+/)[0].to_i
end

#portInt

The port for the proxy.

Returns:

  • (Int)


46
47
48
# File 'lib/hidemyass/proxy.rb', line 46

def port
  @port ||= @row.at_xpath('td[2]/text()').text.strip.to_i
end

#rel_urlString

The relative URL without the leading protocol.

Returns:

  • (String)


94
95
96
# File 'lib/hidemyass/proxy.rb', line 94

def rel_url
  "#{ip}:#{port}"
end

#secure?Boolean

If the proxy’s anonymity is at least high and protocol is encrypted.

Returns:

  • (Boolean)


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

def secure?
  anonym? && ssl?
end

#socks?Boolean

If the proxy’s network protocol is SOCKS.

Returns:

  • (Boolean)


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

def socks?
  protocol.start_with? 'socks'
end

#speedInt

The average response time in milliseconds.

Returns:

  • (Int)


61
62
63
64
# File 'lib/hidemyass/proxy.rb', line 61

def speed
  @speed ||= @row.at_xpath('td[4]/div/div/p/text()')
                 .text.scan(/^\d+/)[0].to_i
end

#ssl?Boolean

If the proxy supports SSL encryption.

Returns:

  • (Boolean)


129
130
131
# File 'lib/hidemyass/proxy.rb', line 129

def ssl?
  https? || socks?
end

#typeString Also known as: protocol

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

Returns:

  • (String)


70
71
72
# File 'lib/hidemyass/proxy.rb', line 70

def type
  @type ||= @row.at_xpath('td[5]/text()').text.strip.split.last.downcase!
end

#urlString

The complete URL of that proxy server.

Returns:

  • (String)


101
102
103
# File 'lib/hidemyass/proxy.rb', line 101

def url
  "#{protocol}://#{rel_url}"
end