proxy_service 1.1.2 → 1.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: 7fdfe384bfb35ffcb1e776646c6b209d7f783415
4
- data.tar.gz: cae3bb440cf6fcebabc4e10914dde221dcf9906c
3
+ metadata.gz: 8f89ee4d44eb50706b723857def75d68bdff776e
4
+ data.tar.gz: cdf2218d01930082f6458b36aa6c456bda1098e9
5
5
  SHA512:
6
- metadata.gz: 62e29c6ab4d4c00140f4bd4b4cd7d2589968cef81b86d95fe92feb52a1e221e73b2a7ab9577a7e4d8989add8d2fbf95475ef3d7f29e37f95e922f996a4b7d6a9
7
- data.tar.gz: 8ebabc07fb86da716f1dc175449c71e87e9fe37681308229094a155e671cb8504a3dc89140fba4a0602c3fdd9a2295e1bde87919a85d73c65302a1cc5be42095
6
+ metadata.gz: 6a2c9c742f8b0a658e3a3446f32a497a038eee1c9044658fcbe9dd4d88e770c113dd5d7fba4994bc6fa4727e2cad36315ce83a61e7f52fdce2c45b5fceb90afc
7
+ data.tar.gz: f8f805752e8b0881e1a8eda7dfc7c9245786728da4ea4f2044a3f02b8b532bdc4eed6d9e2797df4b607e2912a7fa4cb63218fa7aef375eb7f1cdb2d3c7096727
data/README.md CHANGED
@@ -21,9 +21,11 @@ Configure the service, for example, in an initializer
21
21
  ```ruby
22
22
  ProxyService.configure do |config|
23
23
  config.proxies_enabled = true
24
- config.username = '...' # only used when proxies enabled
25
- config.password = '...' # only used when proxies enabled
26
- config.failure_limit = 3 # only used when proxies enabled
24
+ # only used when proxies enabled
25
+ config.username = '...'
26
+ config.password = '...'
27
+ config.failure_limit = 3
28
+ config.failure_codes = %w[503 403] # used to determine if the proxy has been blocked
27
29
  end
28
30
  ```
29
31
  And then use it in your app
data/lib/proxy_service.rb CHANGED
@@ -3,26 +3,28 @@ require 'json'
3
3
  class ProxyService
4
4
 
5
5
  class << self
6
- attr_accessor :proxies_enabled, :username, :password, :failure_limit
6
+ attr_accessor :proxies_enabled, :username, :password, :failure_limit, :failure_codes
7
7
 
8
8
  def configure
9
9
  yield self
10
10
  end
11
11
  end
12
12
 
13
- attr_accessor :source, :failure_limit
13
+ attr_accessor :source, :failure_limit, :failure_codes
14
14
  attr_writer :proxies_enabled
15
15
 
16
16
  # = Create a new proxy service with for a specific ODS
17
17
  #
18
- # @param [String|Symbol] source name of the ODS (e.g. :tripadvisor), will look for a queue with that name "proxy/#{source}"
18
+ # @param [String, Symbol] source name of the ODS (e.g. :trip_advisor), will look for a queue with that name "proxy/#{source}"
19
19
  # @param [Hash] options
20
20
  # @option options [Boolean] :proxies_enabled override the class configuration
21
21
  # @option options [Integer] :failure_limit before blocking the proxy
22
+ # @option options [Array] :failure_codes that indicate a proxy was blocked by the site
22
23
  def initialize(source, options = {})
23
24
  @source = source
24
25
  @proxies_enabled = options.fetch(:proxies_enabled, !!self.class.proxies_enabled)
25
26
  @failure_limit = options.fetch(:failure_limit, self.class.failure_limit || 3)
27
+ @failure_codes = options.fetch(:failure_codes, self.class.failure_codes || %w[403])
26
28
  end
27
29
 
28
30
  # @yield [agent] Passes a [proxied] Mechanize agent to the block
@@ -33,7 +35,7 @@ class ProxyService
33
35
  yield agent
34
36
  proxy.reset_failures
35
37
  rescue Mechanize::ResponseCodeError => e
36
- if e.response_code == '403' # "forbidden"
38
+ if failure_codes.include?(e.response_code)
37
39
  if proxy.failures >= failure_limit
38
40
  proxy.blocked!
39
41
  else
@@ -1,3 +1,3 @@
1
1
  class ProxyService
2
- VERSION = '1.1.2'
2
+ VERSION = '1.1.3'
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.2
4
+ version: 1.1.3
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-01-22 00:00:00.000000000 Z
11
+ date: 2015-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler