proxy_service 1.1.2 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +5 -3
- data/lib/proxy_service.rb +6 -4
- data/lib/proxy_service/version.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: 8f89ee4d44eb50706b723857def75d68bdff776e
|
4
|
+
data.tar.gz: cdf2218d01930082f6458b36aa6c456bda1098e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
25
|
-
config.
|
26
|
-
config.
|
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
|
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
|
38
|
+
if failure_codes.include?(e.response_code)
|
37
39
|
if proxy.failures >= failure_limit
|
38
40
|
proxy.blocked!
|
39
41
|
else
|
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
|
+
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-
|
11
|
+
date: 2015-01-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|