class ProxyFetcher::Client::ProxiesRegistry
ProxyFetcher
proxies registry for managing proxy lists used by the Client
. It is used to fetch proxy lists and instantiate Manager
object that will handle proxies.
Public Class Methods
find_proxy_for(url)
click to toggle source
Searches for valid proxy or required type (HTTP or secure) for requested URL. If no proxy found, than it refreshes proxy list and tries again.
@param url [String]
URL to process with proxy
@return [ProxyFetcher::Proxy]
gems proxy object
# File lib/proxy_fetcher/client/proxies_registry.rb, line 31 def find_proxy_for(url) proxy = if URI.parse(url).is_a?(URI::HTTPS) manager.proxies.detect(&:ssl?) else manager.get end return proxy unless proxy.nil? manager.refresh_list! find_proxy_for(url) end
invalidate_proxy!(proxy)
click to toggle source
Removes proxy from the list of the current proxy manager instance. If no more proxy available, refreshes the list.
@param proxy [ProxyFetcher::Proxy]
proxy object to remove
# File lib/proxy_fetcher/client/proxies_registry.rb, line 16 def invalidate_proxy!(proxy) manager.proxies.delete(proxy) manager.refresh_list! if manager.proxies.empty? end
manager()
click to toggle source
Instantiates or returns ProxyFetcher::Manager
instance for current Thread
.
@return [ProxyFetcher::Manager]
ProxyFetcher manager class
# File lib/proxy_fetcher/client/proxies_registry.rb, line 50 def manager manager = Thread.current[:proxy_fetcher_manager] return manager unless manager.nil? Thread.current[:proxy_fetcher_manager] = ProxyFetcher::Manager.new end