proxy_fetcher 0.15.0 → 0.15.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bf6591a8ede2c142fca7f433f3edceb407ed884c1dee6a98e3ca33efbae392e2
4
- data.tar.gz: 7d7259da718adec21b8d749d04faf594fa926389e570be6c55bbe9ebf3695783
3
+ metadata.gz: 071dd5bfeaf01174bf803981de6147f999e75b99a2d03c32e034b72dd5dc7c82
4
+ data.tar.gz: 1675ce07491e0cbce401c2a113ee7eccdcba0c4cf42ba7e380ad63be988ec91a
5
5
  SHA512:
6
- metadata.gz: 90eed5f390d122ae58f9bd6c7553b7a1ff6bbca8e65c05406593f53b7a00a4ed160120ae62d0ce8289965810aaa3795287769ee9ef12f9404d805694a8ac0cff
7
- data.tar.gz: 31a5b4fcd6199dfc75ca3e89c7bddcc82533ca171f86954e50d4ff44716d73f1ad014f921a05e9eb2fd38a83c5e603eec1fbbf9530b4c01153f6780877388501
6
+ metadata.gz: 42037b0b55109b535e25284815a096154c79bca2f58b107311f5c53da5b9ec0242ab39a6dd9bae48ef3e863c7f43251167180266578ac177887bd3a63215ef1e
7
+ data.tar.gz: 188dd298f8ea03e5985d89e97f99a12ef5d5384eae03a78f9b77e5172c28ae5990dec64795817d52ea6895395679a6c2f2deafafa3f8617154afb32fc06bc972
data/CHANGELOG.md CHANGED
@@ -6,6 +6,16 @@ Reverse Chronological Order:
6
6
 
7
7
  ...
8
8
 
9
+ ## `0.15.1` (2021-02-17)
10
+
11
+ * Support for Ruby 3.0
12
+
13
+ ## `0.15.0` (2021-01-26)
14
+
15
+ * Removed failing providers
16
+ * Added new
17
+ * Specs refactoring
18
+
9
19
  ## `0.14.0` (2020-05-11)
10
20
 
11
21
  * Add MTPro provider
data/Gemfile CHANGED
@@ -6,9 +6,11 @@ gemspec
6
6
 
7
7
  gem "nokogiri", "~> 1.8"
8
8
  gem "oga", "~> 3.2"
9
- gem "rubocop", "~> 0.80"
9
+ gem "rubocop", "~> 1.0"
10
10
 
11
11
  group :test do
12
12
  gem "coveralls", require: false
13
+ # Until I find a way to introduce other MITM proxy
14
+ gem "webrick", "1.4.2"
13
15
  gem "evil-proxy", "~> 0.2"
14
16
  end
@@ -8,6 +8,6 @@ gem "nokogiri", "~> 1.8"
8
8
 
9
9
  group :test do
10
10
  gem "coveralls", require: false
11
+ gem "webrick"
11
12
  gem "evil-proxy", "~> 0.2"
12
- gem "rspec", "~> 3.9"
13
13
  end
data/gemfiles/oga.gemfile CHANGED
@@ -8,6 +8,6 @@ gem "oga", "~> 3.0"
8
8
 
9
9
  group :test do
10
10
  gem "coveralls", require: false
11
+ gem "webrick"
11
12
  gem "evil-proxy", "~> 0.2"
12
- gem "rspec", "~> 3.9"
13
13
  end
data/lib/proxy_fetcher.rb CHANGED
@@ -4,47 +4,47 @@ require "uri"
4
4
  require "http"
5
5
  require "logger"
6
6
 
7
- require File.dirname(__FILE__) + "/proxy_fetcher/version"
7
+ require "#{File.dirname(__FILE__)}/proxy_fetcher/version"
8
8
 
9
- require File.dirname(__FILE__) + "/proxy_fetcher/exceptions"
10
- require File.dirname(__FILE__) + "/proxy_fetcher/configuration"
11
- require File.dirname(__FILE__) + "/proxy_fetcher/configuration/providers_registry"
12
- require File.dirname(__FILE__) + "/proxy_fetcher/proxy"
13
- require File.dirname(__FILE__) + "/proxy_fetcher/manager"
14
- require File.dirname(__FILE__) + "/proxy_fetcher/null_logger"
9
+ require "#{File.dirname(__FILE__)}/proxy_fetcher/exceptions"
10
+ require "#{File.dirname(__FILE__)}/proxy_fetcher/configuration"
11
+ require "#{File.dirname(__FILE__)}/proxy_fetcher/configuration/providers_registry"
12
+ require "#{File.dirname(__FILE__)}/proxy_fetcher/proxy"
13
+ require "#{File.dirname(__FILE__)}/proxy_fetcher/manager"
14
+ require "#{File.dirname(__FILE__)}/proxy_fetcher/null_logger"
15
15
 
16
- require File.dirname(__FILE__) + "/proxy_fetcher/utils/http_client"
17
- require File.dirname(__FILE__) + "/proxy_fetcher/utils/proxy_validator"
18
- require File.dirname(__FILE__) + "/proxy_fetcher/utils/proxy_list_validator"
19
- require File.dirname(__FILE__) + "/proxy_fetcher/client/client"
20
- require File.dirname(__FILE__) + "/proxy_fetcher/client/request"
21
- require File.dirname(__FILE__) + "/proxy_fetcher/client/proxies_registry"
16
+ require "#{File.dirname(__FILE__)}/proxy_fetcher/utils/http_client"
17
+ require "#{File.dirname(__FILE__)}/proxy_fetcher/utils/proxy_validator"
18
+ require "#{File.dirname(__FILE__)}/proxy_fetcher/utils/proxy_list_validator"
19
+ require "#{File.dirname(__FILE__)}/proxy_fetcher/client/client"
20
+ require "#{File.dirname(__FILE__)}/proxy_fetcher/client/request"
21
+ require "#{File.dirname(__FILE__)}/proxy_fetcher/client/proxies_registry"
22
22
 
23
- require File.dirname(__FILE__) + "/proxy_fetcher/document"
24
- require File.dirname(__FILE__) + "/proxy_fetcher/document/adapters"
25
- require File.dirname(__FILE__) + "/proxy_fetcher/document/node"
26
- require File.dirname(__FILE__) + "/proxy_fetcher/document/adapters/abstract_adapter"
27
- require File.dirname(__FILE__) + "/proxy_fetcher/document/adapters/nokogiri_adapter"
28
- require File.dirname(__FILE__) + "/proxy_fetcher/document/adapters/oga_adapter"
23
+ require "#{File.dirname(__FILE__)}/proxy_fetcher/document"
24
+ require "#{File.dirname(__FILE__)}/proxy_fetcher/document/adapters"
25
+ require "#{File.dirname(__FILE__)}/proxy_fetcher/document/node"
26
+ require "#{File.dirname(__FILE__)}/proxy_fetcher/document/adapters/abstract_adapter"
27
+ require "#{File.dirname(__FILE__)}/proxy_fetcher/document/adapters/nokogiri_adapter"
28
+ require "#{File.dirname(__FILE__)}/proxy_fetcher/document/adapters/oga_adapter"
29
29
 
30
30
  ##
31
31
  # Ruby / JRuby lib for managing proxies
32
32
  module ProxyFetcher
33
33
  # ProxyFetcher providers namespace
34
34
  module Providers
35
- require File.dirname(__FILE__) + "/proxy_fetcher/providers/base"
36
- require File.dirname(__FILE__) + "/proxy_fetcher/providers/free_proxy_list"
37
- require File.dirname(__FILE__) + "/proxy_fetcher/providers/free_proxy_list_socks"
38
- require File.dirname(__FILE__) + "/proxy_fetcher/providers/free_proxy_list_ssl"
39
- require File.dirname(__FILE__) + "/proxy_fetcher/providers/free_proxy_list_us"
40
- require File.dirname(__FILE__) + "/proxy_fetcher/providers/http_tunnel"
41
- require File.dirname(__FILE__) + "/proxy_fetcher/providers/mtpro"
42
- require File.dirname(__FILE__) + "/proxy_fetcher/providers/proxy_list"
43
- require File.dirname(__FILE__) + "/proxy_fetcher/providers/proxypedia"
44
- require File.dirname(__FILE__) + "/proxy_fetcher/providers/proxyscrape_http"
45
- require File.dirname(__FILE__) + "/proxy_fetcher/providers/proxyscrape_socks4"
46
- require File.dirname(__FILE__) + "/proxy_fetcher/providers/proxyscrape_socks5"
47
- require File.dirname(__FILE__) + "/proxy_fetcher/providers/xroxy"
35
+ require "#{File.dirname(__FILE__)}/proxy_fetcher/providers/base"
36
+ require "#{File.dirname(__FILE__)}/proxy_fetcher/providers/free_proxy_list"
37
+ require "#{File.dirname(__FILE__)}/proxy_fetcher/providers/free_proxy_list_socks"
38
+ require "#{File.dirname(__FILE__)}/proxy_fetcher/providers/free_proxy_list_ssl"
39
+ require "#{File.dirname(__FILE__)}/proxy_fetcher/providers/free_proxy_list_us"
40
+ require "#{File.dirname(__FILE__)}/proxy_fetcher/providers/http_tunnel"
41
+ require "#{File.dirname(__FILE__)}/proxy_fetcher/providers/mtpro"
42
+ require "#{File.dirname(__FILE__)}/proxy_fetcher/providers/proxy_list"
43
+ require "#{File.dirname(__FILE__)}/proxy_fetcher/providers/proxypedia"
44
+ require "#{File.dirname(__FILE__)}/proxy_fetcher/providers/proxyscrape_http"
45
+ require "#{File.dirname(__FILE__)}/proxy_fetcher/providers/proxyscrape_socks4"
46
+ require "#{File.dirname(__FILE__)}/proxy_fetcher/providers/proxyscrape_socks5"
47
+ require "#{File.dirname(__FILE__)}/proxy_fetcher/providers/xroxy"
48
48
  end
49
49
 
50
50
  @__config_access_lock__ = Mutex.new
@@ -41,15 +41,15 @@ module ProxyFetcher
41
41
  # @return [String]
42
42
  # response body (requested resource content)
43
43
  #
44
- def self.execute(args)
45
- new(args).execute
44
+ def self.execute(**args)
45
+ new(**args).execute
46
46
  end
47
47
 
48
48
  # Initialize new HTTP request
49
49
  #
50
50
  # @return [Request]
51
51
  #
52
- def initialize(args)
52
+ def initialize(**args)
53
53
  raise ArgumentError, "args must be a Hash!" unless args.is_a?(Hash)
54
54
 
55
55
  @url = args.fetch(:url)
@@ -114,7 +114,7 @@ module ProxyFetcher
114
114
 
115
115
  # Sets default configuration options
116
116
  def reset!
117
- @logger = Logger.new(STDOUT)
117
+ @logger = Logger.new($stdout)
118
118
  @user_agent = DEFAULT_USER_AGENT
119
119
  @pool_size = 10
120
120
  @client_timeout = 3
@@ -83,7 +83,7 @@ module ProxyFetcher
83
83
  def clear(text)
84
84
  return "" if text.nil? || text.empty?
85
85
 
86
- text.strip.gsub(/[\t]/i, "")
86
+ text.strip.gsub(/\t/i, "")
87
87
  end
88
88
  end
89
89
  end
@@ -41,8 +41,8 @@ module ProxyFetcher
41
41
  # @return [String]
42
42
  # resource content
43
43
  #
44
- def self.fetch(*args)
45
- new(*args).fetch
44
+ def self.fetch(*args, **kwargs, &block)
45
+ new(*args, **kwargs, &block).fetch
46
46
  end
47
47
 
48
48
  # Initialize HTTP client instance
@@ -51,15 +51,17 @@ module ProxyFetcher
51
51
  #
52
52
  def initialize(url, method: :get, params: {}, headers: {})
53
53
  @url = url.to_s
54
- @method = method
54
+ @method = method.to_sym
55
55
  @params = params
56
56
  @headers = headers
57
57
 
58
- @http = HTTP.headers(default_headers.merge(headers)).timeout(connect: timeout, read: timeout)
59
- @timeout = ProxyFetcher.config.provider_proxies_load_timeout
58
+ unless HTTP::Request::METHODS.include?(@method)
59
+ raise ArgumentError, "'#{@method}' is a wrong HTTP method name"
60
+ end
60
61
 
61
- @ssl_ctx = OpenSSL::SSL::SSLContext.new
62
- @ssl_ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE
62
+ @timeout = ProxyFetcher.config.provider_proxies_load_timeout
63
+ @http = build_http_engine
64
+ @ssl_ctx = build_ssl_context
63
65
  end
64
66
 
65
67
  # Fetches resource content by sending HTTP request to it.
@@ -67,8 +69,10 @@ module ProxyFetcher
67
69
  # @return [String]
68
70
  # response body
69
71
  #
70
- def fetch
71
- response = process_http_request
72
+ def fetch(**options)
73
+ response = perform_http_request
74
+ return response if options.fetch(:raw, false)
75
+
72
76
  response.body.to_s
73
77
  rescue StandardError => e
74
78
  ProxyFetcher.config.logger.warn("Failed to process request to #{url} (#{e.message})")
@@ -77,13 +81,20 @@ module ProxyFetcher
77
81
 
78
82
  protected
79
83
 
80
- def process_http_request(http_method: method, http_params: params)
81
- unless HTTP::Request::METHODS.include?(http_method)
82
- raise ArgumentError, "'#{http_method}' is a wrong HTTP method name!"
84
+ def build_ssl_context
85
+ OpenSSL::SSL::SSLContext.new.tap do |context|
86
+ context.verify_mode = OpenSSL::SSL::VERIFY_NONE
83
87
  end
88
+ end
89
+
90
+ def build_http_engine
91
+ HTTP.headers(default_headers.merge(headers)).timeout(connect: timeout, read: timeout)
92
+ end
84
93
 
94
+ def perform_http_request(http_method: method, http_params: params)
85
95
  http.public_send(
86
- http_method.to_sym, url,
96
+ http_method,
97
+ url,
87
98
  form: http_params,
88
99
  ssl_context: ssl_ctx
89
100
  )
@@ -15,7 +15,7 @@ module ProxyFetcher
15
15
  # Minor version number
16
16
  MINOR = 15
17
17
  # Smallest version number
18
- TINY = 0
18
+ TINY = 1
19
19
 
20
20
  # Full version number
21
21
  STRING = [MAJOR, MINOR, TINY].compact.join(".")
@@ -9,8 +9,8 @@ Gem::Specification.new do |gem|
9
9
  gem.version = ProxyFetcher.gem_version
10
10
  gem.summary = "Ruby gem for dealing with proxy lists from different providers"
11
11
  gem.description = <<-TEXT.strip.gsub(/[\s\n]+/, " ")
12
- This gem can help your Ruby application to make HTTP(S) requests
13
- using proxies by fetching and validating proxy lists from
12
+ This gem can help your Ruby application to make HTTP(S) requests
13
+ using proxies by fetching and validating proxy lists from
14
14
  the different providers.
15
15
  TEXT
16
16
  gem.authors = ["Nikita Bulai"]
@@ -3,6 +3,11 @@
3
3
  require "spec_helper"
4
4
  require "json"
5
5
 
6
+ begin
7
+ require "webrick"
8
+ rescue LoadError
9
+ # nop
10
+ end
6
11
  require "evil-proxy"
7
12
  require "evil-proxy/async"
8
13
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: proxy_fetcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.0
4
+ version: 0.15.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nikita Bulai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-26 00:00:00.000000000 Z
11
+ date: 2021-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http
@@ -143,8 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
143
  - !ruby/object:Gem::Version
144
144
  version: '0'
145
145
  requirements: []
146
- rubyforge_project:
147
- rubygems_version: 2.7.9
146
+ rubygems_version: 3.1.2
148
147
  signing_key:
149
148
  specification_version: 4
150
149
  summary: Ruby gem for dealing with proxy lists from different providers