Class: ActiveProxy::Fetcher
- Inherits:
-
Object
- Object
- ActiveProxy::Fetcher
- Defined in:
- lib/active_proxy/fetcher.rb
Instance Attribute Summary collapse
-
#cache_store ⇒ Object
readonly
Returns the value of attribute cache_store.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#proxy_key ⇒ Object
readonly
Returns the value of attribute proxy_key.
Instance Method Summary collapse
- #current_proxy ⇒ Object
- #format_proxy_full ⇒ Object
- #format_proxy_http ⇒ Object
- #format_proxy_httparty ⇒ Object
- #format_proxy_typhoeus ⇒ Object
-
#initialize(proxy_key, cache_store, options = {}) ⇒ Fetcher
constructor
A new instance of Fetcher.
- #user_agent ⇒ Object
Constructor Details
#initialize(proxy_key, cache_store, options = {}) ⇒ Fetcher
Returns a new instance of Fetcher.
7 8 9 10 11 |
# File 'lib/active_proxy/fetcher.rb', line 7 def initialize(proxy_key, cache_store, = {}) @proxy_key = proxy_key @cache_store = cache_store = end |
Instance Attribute Details
#cache_store ⇒ Object (readonly)
Returns the value of attribute cache_store.
5 6 7 |
# File 'lib/active_proxy/fetcher.rb', line 5 def cache_store @cache_store end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/active_proxy/fetcher.rb', line 5 def end |
#proxy_key ⇒ Object (readonly)
Returns the value of attribute proxy_key.
5 6 7 |
# File 'lib/active_proxy/fetcher.rb', line 5 def proxy_key @proxy_key end |
Instance Method Details
#current_proxy ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/active_proxy/fetcher.rb', line 33 def current_proxy proxy = cache_store.fetch(cache_key("current")) do _proxy = proxy_list.sample "Got new proxy #{_proxy}" _proxy end return proxy unless proxy.nil? cache_store.delete(cache_key("list")) current_proxy end |
#format_proxy_full ⇒ Object
18 19 20 21 22 |
# File 'lib/active_proxy/fetcher.rb', line 18 def format_proxy_full proxy = current_proxy "#{proxy[:type]}://#{proxy[:address]}:#{proxy[:port]}" end |
#format_proxy_http ⇒ Object
28 29 30 31 |
# File 'lib/active_proxy/fetcher.rb', line 28 def format_proxy_http proxy = current_proxy [proxy[:address], proxy[:port]] end |
#format_proxy_httparty ⇒ Object
13 14 15 16 |
# File 'lib/active_proxy/fetcher.rb', line 13 def format_proxy_httparty proxy = current_proxy { http_proxyaddr: proxy[:address], http_proxyport: proxy[:port], timeout: 4 } end |
#format_proxy_typhoeus ⇒ Object
24 25 26 |
# File 'lib/active_proxy/fetcher.rb', line 24 def format_proxy_typhoeus { proxy: format_proxy_full } end |
#user_agent ⇒ Object
44 45 46 |
# File 'lib/active_proxy/fetcher.rb', line 44 def user_agent UserAgentRandomizer::UserAgent.fetch.string end |