proxy_fetcher 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -1
- data/lib/proxy_fetcher/version.rb +1 -1
- data/lib/proxy_fetcher.rb +26 -0
- data/proxy_fetcher.gemspec +1 -1
- data/spec/proxy_fetcher/manager_spec.rb +28 -0
- data/spec/proxy_fetcher/proxy_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5350053943ea06b5eea6f0aae059ae35cda79350
|
4
|
+
data.tar.gz: 8fa58f71797bb165c06d6f8508058c92273b5e8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a137676022ff0ed952383ce6868d2104c18c5ddb2389819525b20f00a97e00c43a2ff4f1366c5125ee8cd6224aa759299f2946e1634eaf2bafe2c705c50f050
|
7
|
+
data.tar.gz: 02ea4aa5f43892386fa4f50ea2fff7b7db432790aef2bcfb42ffa49e6940b97b150ab15a08bc4397d0f49699e3f1908e63a72a66b58b6bd188bfbc0ddd80fe40
|
data/README.md
CHANGED
@@ -86,6 +86,11 @@ Also you can call next instance method for every Proxy object:
|
|
86
86
|
* `uri` (returns `URI::Generic` object)
|
87
87
|
* `url` (returns a formatted URL like "_http://IP:PORT_" )
|
88
88
|
|
89
|
+
You can use two methods to get the first proxy from the list:
|
90
|
+
|
91
|
+
* `get` (will return first proxy and move it to the end of the list)
|
92
|
+
* `get!` (will return first **connectable** proxy and move it to the end of the list; all the proxies till the working one will be removed)
|
93
|
+
|
89
94
|
If you wanna clear current proxy manager list from dead servers, you can just call `cleanup!` method:
|
90
95
|
|
91
96
|
```ruby
|
@@ -104,7 +109,7 @@ manager.cleanup!
|
|
104
109
|
|
105
110
|
## TODO
|
106
111
|
|
107
|
-
|
112
|
+
* Proxy filters
|
108
113
|
|
109
114
|
## Contributing
|
110
115
|
|
data/lib/proxy_fetcher.rb
CHANGED
@@ -37,6 +37,32 @@ module ProxyFetcher
|
|
37
37
|
|
38
38
|
alias_method :fetch!, :refresh_list!
|
39
39
|
|
40
|
+
# Pop just first proxy (and back it to the end of the proxy list)
|
41
|
+
def get
|
42
|
+
first_proxy = @proxies.shift
|
43
|
+
@proxies << first_proxy
|
44
|
+
|
45
|
+
first_proxy
|
46
|
+
end
|
47
|
+
|
48
|
+
alias_method :pop, :get
|
49
|
+
|
50
|
+
# Pop first valid proxy (and back it to the end of the proxy list)
|
51
|
+
# Invalid proxies will be removed from the list
|
52
|
+
def get!
|
53
|
+
index = @proxies.find_index(&:connectable?)
|
54
|
+
return if index < 0
|
55
|
+
|
56
|
+
proxy = @proxies.delete_at(index)
|
57
|
+
tail = @proxies[index..-1]
|
58
|
+
|
59
|
+
@proxies = tail << proxy
|
60
|
+
|
61
|
+
proxy
|
62
|
+
end
|
63
|
+
|
64
|
+
alias_method :pop!, :get!
|
65
|
+
|
40
66
|
# Clean current proxy list from dead proxies (doesn't respond by timeout)
|
41
67
|
def cleanup!
|
42
68
|
proxies.keep_if(&:connectable?)
|
data/proxy_fetcher.gemspec
CHANGED
@@ -5,7 +5,7 @@ require 'proxy_fetcher/version'
|
|
5
5
|
Gem::Specification.new do |gem|
|
6
6
|
gem.name = 'proxy_fetcher'
|
7
7
|
gem.version = ProxyFetcher.gem_version
|
8
|
-
gem.date = '2017-05-
|
8
|
+
gem.date = '2017-05-25'
|
9
9
|
gem.summary = 'Ruby gem for dealing with proxy lists '
|
10
10
|
gem.description = 'This gem can help your Ruby application to make HTTP(S) requests ' \
|
11
11
|
'from proxy server, fetching and validating current proxy lists from the HideMyAss service.'
|
@@ -33,4 +33,32 @@ describe ProxyFetcher::Manager do
|
|
33
33
|
manager = described_class.new(refresh: false)
|
34
34
|
expect(manager.inspect).to eq(manager.to_s)
|
35
35
|
end
|
36
|
+
|
37
|
+
it 'returns first proxy' do
|
38
|
+
manager = described_class.new
|
39
|
+
|
40
|
+
first_proxy = manager.proxies.first
|
41
|
+
|
42
|
+
expect(manager.get).to eq(first_proxy)
|
43
|
+
expect(manager.proxies.first).not_to eq(first_proxy)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'returns first valid proxy' do
|
47
|
+
manager = described_class.new(refresh: false)
|
48
|
+
|
49
|
+
proxies = 5.times.collect { instance_double('ProxyFetcher::Proxy', connectable?: false) }
|
50
|
+
manager.instance_variable_set(:@proxies, proxies)
|
51
|
+
|
52
|
+
connectable_proxy = instance_double('ProxyFetcher::Proxy')
|
53
|
+
allow(connectable_proxy).to receive(:connectable?).and_return(true)
|
54
|
+
|
55
|
+
manager.proxies[0..2].each { |proxy| proxy.instance_variable_set(:@addr, '192.168.1.1') }
|
56
|
+
manager.proxies[2] = connectable_proxy
|
57
|
+
|
58
|
+
expect(manager.get!).to eq(connectable_proxy)
|
59
|
+
expect(manager.proxies.size).to be(3)
|
60
|
+
|
61
|
+
expect(manager.get!).to eq(connectable_proxy)
|
62
|
+
expect(manager.proxies.size).to be(1)
|
63
|
+
end
|
36
64
|
end
|
@@ -18,7 +18,7 @@ describe ProxyFetcher::Proxy do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
it "not connectable if server doesn't respond to head" do
|
21
|
-
allow_any_instance_of(Net::HTTP).to receive(:
|
21
|
+
allow_any_instance_of(Net::HTTP).to receive(:start).and_return(false)
|
22
22
|
expect(proxy.connectable?).to be_falsey
|
23
23
|
end
|
24
24
|
|
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.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nikita Bulai
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|