Module: HideMyAss

Extended by:
HideMyAss, Logger, Request::Actions
Included in:
HideMyAss
Defined in:
lib/hidemyass/ip.rb,
lib/hidemyass.rb,
lib/hidemyass/logger.rb,
lib/hidemyass/railtie.rb,
lib/hidemyass/request.rb,
lib/hidemyass/version.rb,
lib/hidemyass/request/actions.rb,
lib/hidemyass/request/operations.rb

Overview

TODO: Hijack HTTP calls automatically

Defined Under Namespace

Modules: Logger Classes: IP, Railtie, Request

Constant Summary collapse

SITE =
"http://hidemyass.com".freeze
ENDPOINT =
"http://hidemyass.com/proxy-list/".freeze
LOG_PREFIX =
"** [hidemyass]"
VERSION =
"0.2.0"

Instance Method Summary collapse

Methods included from Logger

log, logger, logger=, logging?

Methods included from Request::Actions

delete, get, post, put

Instance Method Details

#clear_cacheObject

Clears cached proxies.



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

def clear_cache
  @proxies = nil
end

#form_dataObject

Form data for HMA search

c[] - Countries p - Port. Defaults to all ports. pr[] - Protocol. 0..2 = HTTP, HTTPS, socks4/5 a[] - Anonymity level. 0..4 = None, Low, Medium, High, High +KA sp[] - Speed. 0..2 = Slow, Medium, Fast. ct[] - Connection time. 0..2 = Slow, Medium, Fast s - Sort. 0..3 = Response time, Connection time, Country A-Z. o - Order. 0, 1 = DESC, ASC. pp - Per Page. 0..3 = 10, 25, 50, 100. sortBy - Sort by. Defaults to date.

Returns form data hash.



88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/hidemyass.rb', line 88

def form_data
  @form_data ||= {
    "c"  => ["Brazil", "Mexico", "United States"],
    "p"  => nil,
    "pr" => [0],
    "a"  => [0,1,2,3],
    "sp" => [2,3],
    "ct" => [2,3],
    "s"  => 0,
    "o"  => 0,
    "pp" => 2,
    "sortBy" => "date"
  }
end

#form_data=(data) ⇒ Object

Sets form data to support custom searches.



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

def form_data=(data)
  @form_data = data if data
end

#hydraObject

Hydra will handle how many requests you can make in parallel.

Typhoeus built-in limit is 200, but this depends heavily on your implementation. If you want to return as soon as you get a successful response, you should set a much, much lower limit, e.g. 10



36
37
38
39
40
41
42
43
44
# File 'lib/hidemyass.rb', line 36

def hydra
  @hydra ||= begin
    opts = if options[:max_concurrency]
      { :max_concurrency => options[:max_concurrency] }
    end

    Typhoeus::Hydra.new(opts || {})
  end
end

#optionsObject



20
21
22
23
24
25
26
27
# File 'lib/hidemyass.rb', line 20

def options
  @options ||= {
    :log   => true,
    :local => false,
    :clear_cache => false,
    :max_concurrency => 10
  }
end

#proxiesObject

Returns HMA proxies.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/hidemyass.rb', line 52

def proxies
  clear_cache if options[:clear_cache]

  @proxies ||= begin
    html = get_hma_body

    html.xpath('//table[@id="listtable"]/tr').collect do |node|
      ip = HideMyAss::IP.new(node.at_xpath('td[2]/span'))
      next unless ip.valid?
      {
        host: ip.address,
        port: node.at_xpath('td[3]').content.strip
      }
    end.compact
  end
end