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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dac8f3b98762e29d5067e32689cef73be6905d4b
4
- data.tar.gz: 5b488bb4180524c2cf64640aa031c9b2604c81cc
3
+ metadata.gz: 5350053943ea06b5eea6f0aae059ae35cda79350
4
+ data.tar.gz: 8fa58f71797bb165c06d6f8508058c92273b5e8b
5
5
  SHA512:
6
- metadata.gz: aa4ff379c85314d81e660c84e65f9772a72b5a0d36110fcda2cff37d4ced8745cc82378bc98d290ab78c4c51868b201504a1067e2741ca3385d285a36bc525a8
7
- data.tar.gz: 2fbc3811ca622aadda97e235b650a8603367fd4851d5a5319e71f994cc4b7520e2e88cbc45d4299c3fd74b58a569d0bf762e35c16eba1aaa9da01b1553759c3d
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
- # Proxy filters
112
+ * Proxy filters
108
113
 
109
114
  ## Contributing
110
115
 
@@ -9,7 +9,7 @@ module ProxyFetcher
9
9
  # Minor version number
10
10
  MINOR = 1
11
11
  # Smallest version number
12
- TINY = 2
12
+ TINY = 3
13
13
 
14
14
  # Full version number
15
15
  STRING = [MAJOR, MINOR, TINY].compact.join('.')
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?)
@@ -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-19'
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(:request_head).and_return(false)
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.2
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-19 00:00:00.000000000 Z
11
+ date: 2017-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri