proxy_fetcher 0.10.0 → 0.10.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/bin/console +14 -0
- data/lib/proxy_fetcher/configuration.rb +10 -9
- data/lib/proxy_fetcher/document.rb +1 -1
- data/lib/proxy_fetcher/document/adapters.rb +1 -1
- data/lib/proxy_fetcher/document/adapters/abstract_adapter.rb +1 -0
- data/lib/proxy_fetcher/providers/base.rb +4 -1
- data/lib/proxy_fetcher/providers/proxy_docker.rb +26 -2
- data/lib/proxy_fetcher/utils/http_client.rb +19 -8
- data/lib/proxy_fetcher/version.rb +1 -1
- data/spec/proxy_fetcher/configuration_spec.rb +3 -1
- data/spec/proxy_fetcher/providers/base_spec.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 90fedddf9296d31071b49be0c44736626987ed973b48395ccfed9b04f0c6ae4a
|
4
|
+
data.tar.gz: 900464a6378e2d72259e54022df01ec1e50ac95f76f9ec613df803ffd0cf2d78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc14dedb91c2a319aa27e3c03b3a881ac0861c378c5b1d8396ca79755f8a80ae86d28e904b999cddafc3f85ad7805ee6386e1fca327ded8a764d60ce572af4a3
|
7
|
+
data.tar.gz: 4d06f65bd36132ae0fbac2c77b12d34b31e5ec851e68995de86457e0d45f29777bcd06ff8c08c6b3e6830a18278f4984e4ca5c3573b7e564c84da155d60a8946
|
data/CHANGELOG.md
CHANGED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'proxy_fetcher'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start(__FILE__)
|
@@ -35,7 +35,11 @@ module ProxyFetcher
|
|
35
35
|
|
36
36
|
# @!attribute [r] adapter
|
37
37
|
# @return [Object] HTML parser adapter
|
38
|
-
|
38
|
+
attr_accessor :adapter
|
39
|
+
|
40
|
+
# @!attribute [r] adapter_class
|
41
|
+
# @return [Object] HTML adapter class
|
42
|
+
attr_reader :adapter_class
|
39
43
|
|
40
44
|
# @!attribute [r] http_client
|
41
45
|
# @return [Object] HTTP client class
|
@@ -120,14 +124,11 @@ module ProxyFetcher
|
|
120
124
|
self.providers = self.class.registered_providers
|
121
125
|
end
|
122
126
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
def adapter=(name_or_class)
|
129
|
-
@adapter = ProxyFetcher::Document::Adapters.lookup(name_or_class)
|
130
|
-
@adapter.setup!
|
127
|
+
def adapter_class
|
128
|
+
return @adapter_class if defined?(@adapter_class)
|
129
|
+
|
130
|
+
@adapter_class = ProxyFetcher::Document::Adapters.lookup(adapter)
|
131
|
+
@adapter_class.setup!
|
131
132
|
end
|
132
133
|
|
133
134
|
# Setups collection of providers that will be used to fetch proxies.
|
@@ -30,7 +30,7 @@ module ProxyFetcher
|
|
30
30
|
|
31
31
|
case name_or_class
|
32
32
|
when Symbol, String
|
33
|
-
adapter_name = name_or_class.to_s.capitalize
|
33
|
+
adapter_name = "#{name_or_class.to_s.capitalize}#{ADAPTER}"
|
34
34
|
ProxyFetcher::Document.const_get(adapter_name)
|
35
35
|
else
|
36
36
|
name_or_class
|
@@ -74,7 +74,10 @@ module ProxyFetcher
|
|
74
74
|
def build_proxy(*args)
|
75
75
|
to_proxy(*args)
|
76
76
|
rescue StandardError => error
|
77
|
-
ProxyFetcher.logger.warn(
|
77
|
+
ProxyFetcher.logger.warn(
|
78
|
+
"Failed to build Proxy object for #{self.class.name} due to error: #{error.message}"
|
79
|
+
)
|
80
|
+
|
78
81
|
nil
|
79
82
|
end
|
80
83
|
|
@@ -6,6 +6,8 @@ module ProxyFetcher
|
|
6
6
|
module Providers
|
7
7
|
# ProxyDocker provider class.
|
8
8
|
class ProxyDocker < Base
|
9
|
+
attr_reader :cookie, :token
|
10
|
+
|
9
11
|
# Provider URL to fetch proxy list
|
10
12
|
def provider_url
|
11
13
|
'https://www.proxydocker.com/en/api/proxylist/'
|
@@ -17,7 +19,7 @@ module ProxyFetcher
|
|
17
19
|
|
18
20
|
def provider_params
|
19
21
|
{
|
20
|
-
token:
|
22
|
+
token: @token,
|
21
23
|
country: 'all',
|
22
24
|
city: 'all',
|
23
25
|
state: 'all',
|
@@ -31,7 +33,7 @@ module ProxyFetcher
|
|
31
33
|
|
32
34
|
def provider_headers
|
33
35
|
{
|
34
|
-
cookie:
|
36
|
+
cookie: @cookie
|
35
37
|
}
|
36
38
|
end
|
37
39
|
|
@@ -44,6 +46,8 @@ module ProxyFetcher
|
|
44
46
|
#
|
45
47
|
# [NOTE] Doesn't support direct filters
|
46
48
|
def load_proxy_list(*)
|
49
|
+
load_dependencies
|
50
|
+
|
47
51
|
json = JSON.parse(load_html(provider_url, {}))
|
48
52
|
json.fetch('proxies', [])
|
49
53
|
rescue JSON::ParserError
|
@@ -70,6 +74,8 @@ module ProxyFetcher
|
|
70
74
|
end
|
71
75
|
end
|
72
76
|
|
77
|
+
private
|
78
|
+
|
73
79
|
def types_mapping
|
74
80
|
{
|
75
81
|
'16' => ProxyFetcher::Proxy::HTTP,
|
@@ -80,6 +86,24 @@ module ProxyFetcher
|
|
80
86
|
'6' => ProxyFetcher::Proxy::HTTP # CON80
|
81
87
|
}
|
82
88
|
end
|
89
|
+
|
90
|
+
def load_dependencies
|
91
|
+
client = ProxyFetcher.config.http_client.new('https://www.proxydocker.com')
|
92
|
+
response = client.fetch_with_headers
|
93
|
+
|
94
|
+
@cookie = load_cookie_from(response)
|
95
|
+
@token = load_token_from(response)
|
96
|
+
end
|
97
|
+
|
98
|
+
def load_cookie_from(response)
|
99
|
+
cookie_headers = (response.headers['Set-Cookie'] || [])
|
100
|
+
cookie_headers.join('; ')
|
101
|
+
end
|
102
|
+
|
103
|
+
def load_token_from(response)
|
104
|
+
html = response.body.to_s
|
105
|
+
html[/meta\s+name\s*=["']_token["']\s+content.+["'](.+?)["']\s*>/i, 1]
|
106
|
+
end
|
83
107
|
end
|
84
108
|
|
85
109
|
ProxyFetcher::Configuration.register_provider(:proxy_docker, ProxyDocker)
|
@@ -68,21 +68,32 @@ module ProxyFetcher
|
|
68
68
|
# response body
|
69
69
|
#
|
70
70
|
def fetch
|
71
|
-
|
72
|
-
response = if method == :post
|
73
|
-
http.post(url, form: params, ssl_context: ssl_ctx)
|
74
|
-
else
|
75
|
-
http.get(url, ssl_context: ssl_ctx)
|
76
|
-
end
|
77
|
-
|
71
|
+
response = process_http_request
|
78
72
|
response.body.to_s
|
79
73
|
rescue StandardError => error
|
80
|
-
ProxyFetcher.logger.warn("Failed to
|
74
|
+
ProxyFetcher.logger.warn("Failed to process request to #{url} (#{error.message})")
|
81
75
|
''
|
82
76
|
end
|
83
77
|
|
78
|
+
def fetch_with_headers
|
79
|
+
process_http_request
|
80
|
+
rescue StandardError => error
|
81
|
+
ProxyFetcher.logger.warn("Failed to process request to #{url} (#{error.message})")
|
82
|
+
HTTP::Response.new(version: '1.1', status: 500, body: '')
|
83
|
+
end
|
84
|
+
|
84
85
|
protected
|
85
86
|
|
87
|
+
def process_http_request(http_method: method, http_params: params)
|
88
|
+
raise ArgumentError, 'wrong http method name!' unless HTTP::Request::METHODS.include?(http_method)
|
89
|
+
|
90
|
+
http.public_send(
|
91
|
+
http_method.to_sym, url,
|
92
|
+
form: http_params,
|
93
|
+
ssl_context: ssl_ctx
|
94
|
+
)
|
95
|
+
end
|
96
|
+
|
86
97
|
# Default HTTP client headers
|
87
98
|
#
|
88
99
|
# @return [Hash]
|
@@ -68,7 +68,9 @@ describe ProxyFetcher::Configuration do
|
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
|
-
|
71
|
+
ProxyFetcher.config.adapter = CustomAdapter
|
72
|
+
|
73
|
+
expect { ProxyFetcher::Manager.new }
|
72
74
|
.to raise_error(ProxyFetcher::Exceptions::AdapterSetupError)
|
73
75
|
|
74
76
|
ProxyFetcher.instance_variable_set('@config', old_config)
|
@@ -44,7 +44,7 @@ describe ProxyFetcher::Providers::Base do
|
|
44
44
|
|
45
45
|
allow_any_instance_of(HTTP::Client).to receive(:get).and_raise(StandardError)
|
46
46
|
|
47
|
-
expect(logger).to receive(:warn).with(/Failed to
|
47
|
+
expect(logger).to receive(:warn).with(/Failed to process request to http[s:\/]/)
|
48
48
|
|
49
49
|
ProxyFetcher::Manager.new
|
50
50
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: proxy_fetcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.10.
|
4
|
+
version: 0.10.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nikita Bulai
|
@@ -56,6 +56,7 @@ description: This gem can help your Ruby application to make HTTP(S) requests us
|
|
56
56
|
proxies by fetching and validating proxy lists from the different providers.
|
57
57
|
email: bulajnikita@gmail.com
|
58
58
|
executables:
|
59
|
+
- console
|
59
60
|
- proxy_fetcher
|
60
61
|
extensions: []
|
61
62
|
extra_rdoc_files: []
|
@@ -66,6 +67,7 @@ files:
|
|
66
67
|
- Gemfile
|
67
68
|
- LICENSE
|
68
69
|
- Rakefile
|
70
|
+
- bin/console
|
69
71
|
- bin/proxy_fetcher
|
70
72
|
- gemfiles/nokogiri.gemfile
|
71
73
|
- gemfiles/oga.gemfile
|