diff --git a/CHANGELOG.md b/CHANGELOG.md index bb40737..8d0935c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,15 @@ Reverse Chronological Order: * Add your description here +## `0.12.0` (2020-01-28) + +* Fix XRoxy provider +* Fix multi-threading issues with config and adapter + +## `0.11.0` (2019-10-24) + +* Big gem refactoring + ## `0.10.2` (2019-03-15) * Remove ProxyDocker provider (no longer workable) diff --git a/lib/proxy_fetcher.rb b/lib/proxy_fetcher.rb index 2caeca9..07dcf3b 100644 --- a/lib/proxy_fetcher.rb +++ b/lib/proxy_fetcher.rb @@ -41,8 +41,12 @@ module Providers require File.dirname(__FILE__) + "/proxy_fetcher/providers/xroxy" end + @__config_access_lock__ = Mutex.new + @__config_definition_lock__ = Mutex.new + # Main ProxyFetcher module. class << self + ## # Returns ProxyFetcher configuration. # @@ -58,7 +62,9 @@ class << self # @providers=[:free_proxy_list, ...], @adapter=ProxyFetcher::Document::NokogiriAdapter> # def config - @config ||= ProxyFetcher::Configuration.new + @__config_definition_lock__.synchronize do + @config ||= ProxyFetcher::Configuration.new + end end ## @@ -70,7 +76,7 @@ def config # Configuration object. # def configure - yield config + @__config_access_lock__.synchronize { yield config } end # Returns ProxyFetcher logger instance. diff --git a/lib/proxy_fetcher/configuration.rb b/lib/proxy_fetcher/configuration.rb index 7e5d235..699ff4c 100644 --- a/lib/proxy_fetcher/configuration.rb +++ b/lib/proxy_fetcher/configuration.rb @@ -39,7 +39,7 @@ class Configuration attr_accessor :logger # @!attribute [r] adapter - # @return [Object] HTML parser adapter + # @return [#to_s] HTML parser adapter attr_reader :adapter # @!attribute [r] http_client @@ -68,6 +68,8 @@ class Configuration # DEFAULT_ADAPTER = :nokogiri + @__adapter_lock__ = Mutex.new + class << self # Registry for handling proxy providers. # @@ -131,11 +133,13 @@ def adapter=(value) end def adapter_class - return @adapter_class if defined?(@adapter_class) + self.class.instance_variable_get(:@__adapter_lock__).synchronize do + return @adapter_class if defined?(@adapter_class) - @adapter_class = ProxyFetcher::Document::Adapters.lookup(adapter) - @adapter_class.setup! - @adapter_class + @adapter_class = ProxyFetcher::Document::Adapters.lookup(adapter) + @adapter_class.setup! + @adapter_class + end end # Setups collection of providers that will be used to fetch proxies. diff --git a/lib/proxy_fetcher/providers/xroxy.rb b/lib/proxy_fetcher/providers/xroxy.rb index fd04748..6c6cf7f 100644 --- a/lib/proxy_fetcher/providers/xroxy.rb +++ b/lib/proxy_fetcher/providers/xroxy.rb @@ -6,11 +6,11 @@ module Providers class XRoxy < Base # Provider URL to fetch proxy list def provider_url - "https://www.xroxy.com/free-proxy-lists/" + "https://madison.xroxy.com/proxylist.html" end def xpath - "//div/table/tbody/tr" + "//tr[@class='row1' or @class='row0']" end # Converts HTML node (entry of N tags) to ProxyFetcher::Proxy @@ -24,12 +24,12 @@ def xpath # def to_proxy(html_node) ProxyFetcher::Proxy.new.tap do |proxy| - proxy.addr = html_node.content_at("td[1]") - proxy.port = Integer(html_node.content_at("td[2]").gsub(/^0+/, "")) - proxy.anonymity = html_node.content_at("td[3]") - proxy.country = html_node.content_at("td[5]") - proxy.response_time = Integer(html_node.content_at("td[6]")) - proxy.type = html_node.content_at("td[3]") + proxy.addr = html_node.content_at("td[2]") + proxy.port = Integer(html_node.content_at("td[3]").gsub(/^0+/, "")) + proxy.anonymity = html_node.content_at("td[4]") + proxy.country = html_node.content_at("td[6]") + proxy.response_time = Integer(html_node.content_at("td[7]")) + proxy.type = html_node.content_at("td[4]") end end end diff --git a/lib/proxy_fetcher/version.rb b/lib/proxy_fetcher/version.rb index 39d3446..92b17ee 100644 --- a/lib/proxy_fetcher/version.rb +++ b/lib/proxy_fetcher/version.rb @@ -13,7 +13,7 @@ module VERSION # Major version number MAJOR = 0 # Minor version number - MINOR = 11 + MINOR = 12 # Smallest version number TINY = 0