Class: Ripli::ProxyScan

Inherits:
CustomParser show all
Defined in:
lib/ripli/proxyscan.rb

Constant Summary collapse

BASE_URL =
'https://www.proxyscan.io/download?type='
URL_PARAMS =
{
  https: 'https&timeout=%d&country=all&ssl=all&anonymity=all',
  socks4: 'socks4&timeout=%d&country=all',
  socks5: 'socks5&timeout=%d&country=all'
}.freeze

Constants inherited from CustomParser

CustomParser::DEFAULT_MAX_TIMEOUT, CustomParser::DEFAULT_MECHANIZE_TIMEOUT, CustomParser::LOG_DIR

Instance Method Summary collapse

Methods inherited from CustomParser

#initialize, #shell_exec!

Constructor Details

This class inherits a constructor from Ripli::CustomParser

Instance Method Details

#parse(type, opts = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/ripli/proxyscan.rb', line 15

def parse(type, opts = {})
  max_timeout = opts[:max_timeout] || DEFAULT_MAX_TIMEOUT
  link = [BASE_URL, URL_PARAMS[type] % max_timeout].join
  response = @mechanize.get(link).body

  response.split.map { |proxy| "#{type}\t#{proxy.sub(':', "\t\t")}" }
rescue Net::OpenTimeout, Net::ReadTimeout
  @log.error '[ProxyScrape] Sorry, site is unavailable!'
end