proxy_service 1.1.4 → 1.1.5

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: c8c8e6939900aec1650960d7159aeb75b190a646
4
- data.tar.gz: 39f22e3ae5367e3b8cb16ed8039918848f2c7d36
3
+ metadata.gz: a67a8a9b6a6b147f03393b4ebe5509965468efc2
4
+ data.tar.gz: 1cc38b2a5767af0eb731941abf76dcb36368db8c
5
5
  SHA512:
6
- metadata.gz: 1a7c3d175741b213721435ff03e975b9221f01c8e4674b45ca021dfeb987d122752ba776180639b49262eb3946236dffe2807701f021aaa0cfb6daa69c5bdcc4
7
- data.tar.gz: 07f782d3d3a399a0fcae8cf6ad9a55f9948e6b73f8e06c5eebea0103039a3888f3689e9320e0b65124b0715cd5942a72e98e1dbd71becd9d9f4dae2b56aa5258
6
+ metadata.gz: fdc70d07f3ed024aa0df07bae67eb7ab3ce8a00e476ca3fb4c9af9f605b8cac25a4254b00ba8347fa44d09e26a251c059fecf0f5c7746a7d3f840fca2018137a
7
+ data.tar.gz: 56aeff45fb3aa4babef7992ea397777a67e9cd5f1dea83a67d60ccc6ad898bc845d57eb89f65ace754479447a81817e4932cf92b8ac5ddd5796fec8a01b8729b
data/lib/proxy_service.rb CHANGED
@@ -36,13 +36,9 @@ class ProxyService
36
36
  yield agent
37
37
  proxy.reset_failures
38
38
  rescue Mechanize::ResponseCodeError => e
39
- if failure_codes.include?(e.response_code)
40
- if proxy.failures >= failure_limit
41
- proxy.blocked!
42
- else
43
- proxy.increment_failures
44
- end
45
- end
39
+ block_or_increment_proxy if failure_codes.include?(e.response_code)
40
+ rescue ProxyBlockedError, ReCaptchaError
41
+ block_or_increment_proxy
46
42
  ensure
47
43
  proxy.release
48
44
  end
@@ -51,6 +47,14 @@ class ProxyService
51
47
  # Private
52
48
  #
53
49
 
50
+ def block_or_increment_proxy
51
+ if proxy.failures >= failure_limit
52
+ proxy.blocked!
53
+ else
54
+ proxy.increment_failures
55
+ end
56
+ end
57
+
54
58
  def proxies_enabled?
55
59
  @proxies_enabled
56
60
  end
@@ -77,6 +81,16 @@ class ProxyService
77
81
  NullWorker.new
78
82
  end
79
83
  end
84
+
85
+ #
86
+ # Custom errors
87
+ #
88
+
89
+ class ProxyBlockedError < StandardError
90
+ end
91
+
92
+ class ReCaptchaError < StandardError
93
+ end
80
94
  end
81
95
 
82
96
  require 'proxy_service/mechanize_agent'
@@ -1,3 +1,3 @@
1
1
  class ProxyService
2
- VERSION = '1.1.4'
2
+ VERSION = '1.1.5'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: proxy_service
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
4
+ version: 1.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Buckley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-05 00:00:00.000000000 Z
11
+ date: 2015-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler