Class: ProxyFetcher::Providers::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/proxy_fetcher/providers/base.rb

Overview

Base class for all the ProxyFetcher providers.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.fetch_proxies!(*args) ⇒ Object

Just synthetic sugar to make it easier to call #fetch_proxies! method.



42
43
44
# File 'lib/proxy_fetcher/providers/base.rb', line 42

def self.fetch_proxies!(*args)
  new.fetch_proxies!(*args)
end

Instance Method Details

#fetch_proxies(filters = {}) ⇒ Object Also known as: fetch_proxies!

Loads proxy provider page content, extract proxy list from it and convert every entry to proxy object.



9
10
11
12
13
# File 'lib/proxy_fetcher/providers/base.rb', line 9

def fetch_proxies(filters = {})
  raw_proxies = load_proxy_list(filters)
  proxies = raw_proxies.map { |html_node| build_proxy(html_node) }.compact
  proxies.reject { |proxy| proxy.addr.nil? }
end

#provider_headersHash

Returns Provider headers required to fetch the proxy list.

Returns:

  • (Hash)

    Provider headers required to fetch the proxy list



33
34
35
# File 'lib/proxy_fetcher/providers/base.rb', line 33

def provider_headers
  {}
end

#provider_methodObject



22
23
24
# File 'lib/proxy_fetcher/providers/base.rb', line 22

def provider_method
  :get
end

#provider_paramsObject



26
27
28
# File 'lib/proxy_fetcher/providers/base.rb', line 26

def provider_params
  {}
end

#provider_urlObject

Raises:

  • (NotImplementedError)


18
19
20
# File 'lib/proxy_fetcher/providers/base.rb', line 18

def provider_url
  raise NotImplementedError, "#{__method__} must be implemented in a descendant class!"
end

#xpathObject

Raises:

  • (NotImplementedError)


37
38
39
# File 'lib/proxy_fetcher/providers/base.rb', line 37

def xpath
  raise NotImplementedError, "#{__method__} must be implemented in a descendant class!"
end