content_gateway 0.5.0 → 0.5.1

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: ee3e2f6da92f839d6d66363fb6860fe51ca61ff1
4
- data.tar.gz: 25fcaa57e51bf4f365133c4d5672ce93cb1076e9
3
+ metadata.gz: f61a78669daef3d6d8e315286dfc30b809fff617
4
+ data.tar.gz: dafc8418766cd8db41f12341d2133dfe3e315cb4
5
5
  SHA512:
6
- metadata.gz: 4e95aa8acf647aaa56102fcc5e28ca6fab2f46d0885d3353d9f785003f6a4848d6ee367cbbc2d79a7ef78679e20f0f296d51f2e889ef29dc4515a6d8e21a2db5
7
- data.tar.gz: 79995262957697314650059639726c15d474a199c59c9f96ee377ceadaa9b2c38a0ebbc930c5eededd0ded68f8908112419a9b0ef985919581b2c48389270881
6
+ metadata.gz: d4a10af76e1d83e84826eabd94a95ade5169f8786c200f39b0a00c884a4e98f0140e6d59c1d54220a9efd3985a1d438ce53887f6c73e25ee22bbaaef05679e0b
7
+ data.tar.gz: 5039d46047e9549f72a413e607e0db3cb0cf02e8cd2cbf553e40963aa169702f6a7194379cbf2bf1915d51a80cc7af018635599302fe92ae3e7622796dfbc433
data/Changelog CHANGED
@@ -1,3 +1,7 @@
1
+ 2015-11-19 [0.5.1]
2
+
3
+ * Bugfix proxy implementation wrapper on rest-client
4
+
1
5
  2015-07-24 [0.5.0]
2
6
 
3
7
  * Mapping JSON parse errors to ContentGateway::ParserError
data/Gemfile.lock CHANGED
@@ -2,18 +2,18 @@ PATH
2
2
  remote: .
3
3
  specs:
4
4
  content_gateway (0.5.0)
5
- activesupport
6
- json
7
- rest-client
5
+ activesupport (>= 3)
6
+ json (~> 1.0)
7
+ rest-client (~> 1.0)
8
8
 
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- activesupport (4.1.8)
13
- i18n (~> 0.6, >= 0.6.9)
12
+ activesupport (4.2.5)
13
+ i18n (~> 0.7)
14
14
  json (~> 1.7, >= 1.7.7)
15
15
  minitest (~> 5.1)
16
- thread_safe (~> 0.1)
16
+ thread_safe (~> 0.3, >= 0.3.4)
17
17
  tzinfo (~> 1.1)
18
18
  byebug (3.5.1)
19
19
  columnize (~> 0.8)
@@ -22,13 +22,18 @@ GEM
22
22
  columnize (0.8.9)
23
23
  debugger-linecache (1.2.0)
24
24
  diff-lcs (1.2.5)
25
- i18n (0.6.11)
26
- json (1.8.1)
27
- mime-types (2.4.3)
28
- minitest (5.5.0)
25
+ domain_name (0.5.25)
26
+ unf (>= 0.0.5, < 1.0.0)
27
+ http-cookie (1.0.2)
28
+ domain_name (~> 0.5)
29
+ i18n (0.7.0)
30
+ json (1.8.3)
31
+ mime-types (2.6.2)
32
+ minitest (5.8.3)
29
33
  multi_json (1.7.9)
30
- netrc (0.10.2)
31
- rest-client (1.7.2)
34
+ netrc (0.11.0)
35
+ rest-client (1.8.0)
36
+ http-cookie (>= 1.0.2, < 2.0)
32
37
  mime-types (>= 1.16, < 3.0)
33
38
  netrc (~> 0.7)
34
39
  rspec (3.1.0)
@@ -48,9 +53,12 @@ GEM
48
53
  simplecov-html (~> 0.7.1)
49
54
  simplecov-html (0.7.1)
50
55
  slop (3.6.0)
51
- thread_safe (0.3.4)
56
+ thread_safe (0.3.5)
52
57
  tzinfo (1.2.2)
53
58
  thread_safe (~> 0.1)
59
+ unf (0.1.4)
60
+ unf_ext
61
+ unf_ext (0.0.7.1)
54
62
 
55
63
  PLATFORMS
56
64
  ruby
@@ -60,3 +68,6 @@ DEPENDENCIES
60
68
  content_gateway!
61
69
  rspec (>= 2.3.0)
62
70
  simplecov (>= 0.7.1)
71
+
72
+ BUNDLED WITH
73
+ 1.10.6
data/README.md CHANGED
@@ -33,6 +33,7 @@ Or install it yourself as:
33
33
  - `timeout`: request timeout in seconds
34
34
  - `cache_expires_in`: cache data expiration time, in seconds
35
35
  - `cache_stale_expires_in`: stale cache data expiration time, in seconds
36
+ - `stale_on_error`: if `true`, returns value from cache stale (if available) after a server error. Default value: `true`
36
37
  - `cache`: cache store instance. This may be an instance of `ActiveSupport::Cache`
37
38
  - `proxy`: proxy address, if needed
38
39
 
@@ -43,8 +44,9 @@ config = OpenStruct.new(
43
44
  timeout: 2,
44
45
  cache_expires_in: 1800,
45
46
  cache_stale_expires_in: 86400,
47
+ stale_on_error: false,
46
48
  cache: ActiveSupport::Cache.lookup_store(:memory_store),
47
- proxy: "http://proxy.example.com/"
49
+ proxy: "http://proxy.example.com:3128"
48
50
  )
49
51
  ```
50
52
 
@@ -167,4 +169,4 @@ gateway.post("/api/post_example", payload: { param1: "value" }, ssl_certificate:
167
169
 
168
170
  ## License
169
171
 
170
- Copyright (c) 2014 Globo.com - Webmedia. See [LICENSE.txt](https://github.com/globocom/content-gateway-ruby/blob/master/LICENSE.txt) for more details.
172
+ Copyright (c) 2015 Globo.com - Webmedia. See [LICENSE.txt](https://github.com/globocom/content-gateway-ruby/blob/master/LICENSE.txt) for more details.
@@ -16,9 +16,9 @@ Gem::Specification.new do |gem|
16
16
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
17
  gem.require_paths = ["lib"]
18
18
 
19
- gem.add_dependency "activesupport"
20
- gem.add_dependency "rest-client"
21
- gem.add_dependency "json"
19
+ gem.add_dependency "activesupport", ">= 3"
20
+ gem.add_dependency "rest-client", "~> 1.0"
21
+ gem.add_dependency "json", "~> 1.0"
22
22
 
23
23
  gem.add_development_dependency "rspec", ">= 2.3.0"
24
24
  gem.add_development_dependency "simplecov", ">= 0.7.1"
@@ -17,6 +17,7 @@ module ContentGateway
17
17
  timeout = params[:timeout] || @config.timeout
18
18
  expires_in = params[:expires_in] || @config.cache_expires_in
19
19
  stale_expires_in = params[:stale_expires_in] || @config.cache_stale_expires_in
20
+ stale_on_error = config_stale_on_error params, @config
20
21
 
21
22
  begin
22
23
  Timeout.timeout(timeout) do
@@ -39,6 +40,7 @@ module ContentGateway
39
40
 
40
41
  rescue ContentGateway::ServerError => e
41
42
  begin
43
+ raise e unless stale_on_error
42
44
  serve_stale
43
45
  rescue ContentGateway::StaleCacheNotAvailableError
44
46
  raise e
@@ -56,5 +58,12 @@ module ContentGateway
56
58
  def stale_key
57
59
  @stale_key ||= "stale:#{@url}"
58
60
  end
61
+
62
+ private
63
+ def config_stale_on_error params, config
64
+ return params[:stale_on_error] unless params[:stale_on_error].nil?
65
+ return @config.stale_on_error unless @config.stale_on_error.nil?
66
+ true
67
+ end
59
68
  end
60
69
  end
@@ -6,6 +6,7 @@ module ContentGateway
6
6
  h[:headers] = headers if headers.present?
7
7
  h = load_ssl_params(h, params) if params.has_key?(:ssl_certificate)
8
8
  end
9
+ RestClient.proxy = proxy
9
10
  @client = RestClient::Request.new(data)
10
11
  end
11
12
 
@@ -1,3 +1,3 @@
1
1
  module ContentGateway
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  end
@@ -149,6 +149,30 @@ describe ContentGateway::Gateway do
149
149
  it "should serve stale" do
150
150
  expect(gateway.get(resource_path)).to eql "cached response"
151
151
  end
152
+
153
+ context "when stale_on_error configuration is true" do
154
+ let :gateway do
155
+ config_with_stale_on_error = config.dup
156
+ config_with_stale_on_error.stale_on_error = true
157
+ ContentGateway::Gateway.new "API XPTO", config_with_stale_on_error, url_generator, headers: headers
158
+ end
159
+
160
+ it "should serve stale" do
161
+ expect(gateway.get(resource_path)).to eql "cached response"
162
+ end
163
+ end
164
+
165
+ context "when stale_on_error configuration is false" do
166
+ let :gateway do
167
+ config_with_stale_on_error = config.dup
168
+ config_with_stale_on_error.stale_on_error = false
169
+ ContentGateway::Gateway.new "API XPTO", config_with_stale_on_error, url_generator, headers: headers
170
+ end
171
+
172
+ it "should raise error" do
173
+ expect { gateway.get resource_path }.to raise_error ContentGateway::ServerError
174
+ end
175
+ end
152
176
  end
153
177
  end
154
178
  end
@@ -171,5 +171,17 @@ describe ContentGateway::Request do
171
171
  end
172
172
  end
173
173
  end
174
+
175
+ context "when proxy is used" do
176
+ let(:proxy) { 'http://proxy.test:3128' }
177
+ subject { ContentGateway::Request.new(:get, "/url", {}, {}, proxy) }
178
+ let(:request_params) { { method: :get, url: "/url", proxy: proxy } }
179
+
180
+ it "should set proxy on RestClient" do
181
+ expect(subject.execute).to eql "data"
182
+ expect(RestClient.proxy).to eql(proxy)
183
+ end
184
+ end
185
+
174
186
  end
175
187
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: content_gateway
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Túlio Ornelas
@@ -14,7 +14,7 @@ authors:
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
- date: 2015-07-24 00:00:00.000000000 Z
17
+ date: 2015-11-19 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: activesupport
@@ -22,42 +22,42 @@ dependencies:
22
22
  requirements:
23
23
  - - '>='
24
24
  - !ruby/object:Gem::Version
25
- version: '0'
25
+ version: '3'
26
26
  type: :runtime
27
27
  prerelease: false
28
28
  version_requirements: !ruby/object:Gem::Requirement
29
29
  requirements:
30
30
  - - '>='
31
31
  - !ruby/object:Gem::Version
32
- version: '0'
32
+ version: '3'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: rest-client
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - '>='
37
+ - - ~>
38
38
  - !ruby/object:Gem::Version
39
- version: '0'
39
+ version: '1.0'
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
- - - '>='
44
+ - - ~>
45
45
  - !ruby/object:Gem::Version
46
- version: '0'
46
+ version: '1.0'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: json
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
- - - '>='
51
+ - - ~>
52
52
  - !ruby/object:Gem::Version
53
- version: '0'
53
+ version: '1.0'
54
54
  type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
- - - '>='
58
+ - - ~>
59
59
  - !ruby/object:Gem::Version
60
- version: '0'
60
+ version: '1.0'
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: rspec
63
63
  requirement: !ruby/object:Gem::Requirement
@@ -155,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
155
  version: '0'
156
156
  requirements: []
157
157
  rubyforge_project:
158
- rubygems_version: 2.4.5
158
+ rubygems_version: 2.4.6
159
159
  signing_key:
160
160
  specification_version: 4
161
161
  summary: Content Gateway