content_gateway 0.5.1 → 0.5.2

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: f61a78669daef3d6d8e315286dfc30b809fff617
4
- data.tar.gz: dafc8418766cd8db41f12341d2133dfe3e315cb4
3
+ metadata.gz: '09f4668cfce0325aa25a4deedd9230872b50866f'
4
+ data.tar.gz: 99ae88d63d41897fe28e17784d04858007e78edb
5
5
  SHA512:
6
- metadata.gz: d4a10af76e1d83e84826eabd94a95ade5169f8786c200f39b0a00c884a4e98f0140e6d59c1d54220a9efd3985a1d438ce53887f6c73e25ee22bbaaef05679e0b
7
- data.tar.gz: 5039d46047e9549f72a413e607e0db3cb0cf02e8cd2cbf553e40963aa169702f6a7194379cbf2bf1915d51a80cc7af018635599302fe92ae3e7622796dfbc433
6
+ metadata.gz: e4d825a0913af3a1bb450faa6dddf267d333b06dd237b8e4ee8e15e086d94fdfb1b17f38b8b9d49a0604da73a7dfcd86081312976016cd70cd06696b45f5a855
7
+ data.tar.gz: 1abb95ab7ef05ae2160f42732a6214665327c513e3ed266b47d285cc9248534e954b8f99b2506ea1b2e1f1d7f8c40d89b83719443164f154d37cf8936b112969
@@ -1 +1 @@
1
- ruby-2.0.0-p598
1
+ ruby-2.3.3
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ sudo: false
3
+ script: bundle exec rake spec
data/Changelog CHANGED
@@ -1,3 +1,8 @@
1
+ 2016-12-19 [0.5.2]
2
+
3
+ * Bugfix: Now stale_on_error returns true if theres no config
4
+ * Add default url generator
5
+
1
6
  2015-11-19 [0.5.1]
2
7
 
3
8
  * Bugfix proxy implementation wrapper on rest-client
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
1
  source 'https://rubygems.org'
2
- ruby '2.0.0'
2
+ ruby '2.3.3'
3
+
4
+ gem 'coveralls', require: false
3
5
 
4
6
  gemspec
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- content_gateway (0.5.0)
4
+ content_gateway (0.5.2)
5
5
  activesupport (>= 3)
6
6
  json (~> 1.0)
7
7
  rest-client (~> 1.0)
@@ -9,29 +9,36 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- activesupport (4.2.5)
12
+ activesupport (5.0.0.1)
13
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
14
  i18n (~> 0.7)
14
- json (~> 1.7, >= 1.7.7)
15
15
  minitest (~> 5.1)
16
- thread_safe (~> 0.3, >= 0.3.4)
17
16
  tzinfo (~> 1.1)
18
17
  byebug (3.5.1)
19
18
  columnize (~> 0.8)
20
19
  debugger-linecache (~> 1.2)
21
20
  slop (~> 3.6)
22
21
  columnize (0.8.9)
22
+ concurrent-ruby (1.0.2)
23
+ coveralls (0.7.1)
24
+ multi_json (~> 1.3)
25
+ rest-client
26
+ simplecov (>= 0.7)
27
+ term-ansicolor
28
+ thor
23
29
  debugger-linecache (1.2.0)
24
30
  diff-lcs (1.2.5)
25
- domain_name (0.5.25)
31
+ domain_name (0.5.20161021)
26
32
  unf (>= 0.0.5, < 1.0.0)
27
- http-cookie (1.0.2)
33
+ http-cookie (1.0.3)
28
34
  domain_name (~> 0.5)
29
35
  i18n (0.7.0)
30
36
  json (1.8.3)
31
- mime-types (2.6.2)
32
- minitest (5.8.3)
37
+ mime-types (2.99.3)
38
+ minitest (5.10.1)
33
39
  multi_json (1.7.9)
34
40
  netrc (0.11.0)
41
+ rake (0.9.6)
35
42
  rest-client (1.8.0)
36
43
  http-cookie (>= 1.0.2, < 2.0)
37
44
  mime-types (>= 1.16, < 3.0)
@@ -53,12 +60,16 @@ GEM
53
60
  simplecov-html (~> 0.7.1)
54
61
  simplecov-html (0.7.1)
55
62
  slop (3.6.0)
63
+ term-ansicolor (1.4.0)
64
+ tins (~> 1.0)
65
+ thor (0.19.4)
56
66
  thread_safe (0.3.5)
67
+ tins (1.13.0)
57
68
  tzinfo (1.2.2)
58
69
  thread_safe (~> 0.1)
59
70
  unf (0.1.4)
60
71
  unf_ext
61
- unf_ext (0.0.7.1)
72
+ unf_ext (0.0.7.2)
62
73
 
63
74
  PLATFORMS
64
75
  ruby
@@ -66,8 +77,13 @@ PLATFORMS
66
77
  DEPENDENCIES
67
78
  byebug
68
79
  content_gateway!
80
+ coveralls
81
+ rake
69
82
  rspec (>= 2.3.0)
70
83
  simplecov (>= 0.7.1)
71
84
 
85
+ RUBY VERSION
86
+ ruby 2.3.3p222
87
+
72
88
  BUNDLED WITH
73
- 1.10.6
89
+ 1.13.6
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Content Gateway
2
2
 
3
+ [![Build Status](https://travis-ci.org/globocom/content-gateway-ruby.svg)](https://travis-ci.org/globocom/content-gateway-ruby)
4
+ [![Coverage Status](https://coveralls.io/repos/github/globocom/content-gateway-ruby/badge.svg?branch=master)](https://coveralls.io/github/globocom/content-gateway-ruby?branch=master)
5
+
3
6
  An easy way to get external content with two cache levels. The first is a performance cache and second is the stale.
4
7
 
5
8
  Content Gateway lets you set a timeout for any request.
@@ -56,13 +59,12 @@ config = OpenStruct.new(
56
59
 
57
60
  - a label, which is used in the log messages
58
61
  - a config object, just as described above
59
- - an URL Generator object. This may be any object that responds to a `generate` method, like this:
60
- - an optional hash with default params. Currently, it only supports default headers
62
+ - (optional) an URL Generator object. This may be any object that responds to a `generate` method, like this:
63
+ - (optional) a hash with default params. Currently, it only supports default headers
61
64
 
62
65
  ```ruby
63
66
  class UrlGenerator
64
67
  def generate(resource_path, params = {})
65
- args = ""
66
68
  args = "?#{params.map {|k, v| "#{k}=#{v}"}.join("&")}" if params.any?
67
69
  "http://example.com/#{resource_path}#{args}"
68
70
  end
@@ -73,7 +75,7 @@ default_params = { headers: { Accept: "application/json" } }
73
75
  gateway = ContentGateway::Gateway.new("My API", config, UrlGenerator.new, default_params)
74
76
  ```
75
77
 
76
- Every param may be overrided on each request.
78
+ If ommited, the default URL Generator adds the method call params as query string parameters. Every param may be overrided on each request.
77
79
 
78
80
  This Gateway object supports the following methods:
79
81
 
@@ -169,4 +171,4 @@ gateway.post("/api/post_example", payload: { param1: "value" }, ssl_certificate:
169
171
 
170
172
  ## License
171
173
 
172
- Copyright (c) 2015 Globo.com - Webmedia. See [LICENSE.txt](https://github.com/globocom/content-gateway-ruby/blob/master/LICENSE.txt) for more details.
174
+ Copyright (c) 2016 Globo.com - Webmedia. See [LICENSE.txt](https://github.com/globocom/content-gateway-ruby/blob/master/LICENSE.txt) for more details.
@@ -23,4 +23,5 @@ Gem::Specification.new do |gem|
23
23
  gem.add_development_dependency "rspec", ">= 2.3.0"
24
24
  gem.add_development_dependency "simplecov", ">= 0.7.1"
25
25
  gem.add_development_dependency "byebug"
26
+ gem.add_development_dependency "rake"
26
27
  end
@@ -5,6 +5,7 @@ require "benchmark"
5
5
  require "json"
6
6
  require "rest-client"
7
7
  require "active_support/cache"
8
+ require "active_support/notifications"
8
9
  require "active_support/core_ext/object/blank"
9
10
  require "active_support/core_ext/date_time/calculations"
10
11
  require "active_support/core_ext/hash/indifferent_access"
@@ -62,7 +62,7 @@ module ContentGateway
62
62
  private
63
63
  def config_stale_on_error params, config
64
64
  return params[:stale_on_error] unless params[:stale_on_error].nil?
65
- return @config.stale_on_error unless @config.stale_on_error.nil?
65
+ return config.stale_on_error unless config.try(:stale_on_error).nil?
66
66
  true
67
67
  end
68
68
  end
@@ -3,7 +3,7 @@ module ContentGateway
3
3
  def initialize(label, config, url_generator = nil, default_params = {})
4
4
  @label = label
5
5
  @config = config
6
- @url_generator = url_generator
6
+ @url_generator = url_generator || DefaultUrlGenerator
7
7
  @default_params = default_params
8
8
  end
9
9
 
@@ -212,5 +212,12 @@ module ContentGateway
212
212
  end
213
213
  end.yield
214
214
  end
215
+
216
+ class DefaultUrlGenerator
217
+ def generate(resource_path, params = {})
218
+ args = "?#{params.map {|k, v| "#{k}=#{v}"}.join("&")}" if params.any?
219
+ "#{resource_path}#{args}"
220
+ end
221
+ end
215
222
  end
216
223
  end
@@ -1,3 +1,3 @@
1
1
  module ContentGateway
2
- VERSION = "0.5.1"
2
+ VERSION = "0.5.2"
3
3
  end
@@ -8,11 +8,24 @@ describe ContentGateway::Gateway do
8
8
  end
9
9
 
10
10
  let! :config do
11
- OpenStruct.new(
11
+ class FakeConfig
12
+ attr_accessor :cache, :cache_expires_in, :cache_stale_expires_in, :proxy, :timeout
13
+
14
+ def initialize(params)
15
+ @cache = params[:cache]
16
+ @cache_expires_in = params[:cache_expires_in]
17
+ @cache_stale_expires_in = params[:cache_stale_expires_in]
18
+ @proxy = params[:proxy]
19
+ @timeout = params[:timeout]
20
+ end
21
+ end
22
+
23
+ FakeConfig.new(
12
24
  cache: ActiveSupport::Cache::NullStore.new,
13
25
  cache_expires_in: 15.minutes,
14
26
  cache_stale_expires_in: 1.hour,
15
- proxy: "proxy"
27
+ proxy: "proxy",
28
+ timeout: 2
16
29
  )
17
30
  end
18
31
 
@@ -123,9 +136,10 @@ describe ContentGateway::Gateway do
123
136
  end
124
137
 
125
138
  context "with stale cache" do
139
+ let(:cache_store) {double("cache_store")}
140
+
126
141
  context "on timeout" do
127
142
  before do
128
- cache_store = double("cache_store")
129
143
  allow(cache_store).to receive(:fetch).with(resource_url, expires_in: default_expires_in).and_raise(Timeout::Error)
130
144
  allow(cache_store).to receive(:read).with(stale_cache_key).and_return(cached_response)
131
145
  config.cache = cache_store
@@ -140,36 +154,27 @@ describe ContentGateway::Gateway do
140
154
  before do
141
155
  stub_request_with_error({method: :get, url: resource_url, proxy: config.proxy, headers: headers}, RestClient::InternalServerError.new(nil, 500))
142
156
 
143
- cache_store = double("cache_store")
144
157
  allow(cache_store).to receive(:fetch).with(resource_url, expires_in: default_expires_in).and_yield
145
158
  allow(cache_store).to receive(:read).with(stale_cache_key).and_return(cached_response)
146
159
  config.cache = cache_store
147
160
  end
148
161
 
149
- it "should serve stale" do
150
- expect(gateway.get(resource_path)).to eql "cached response"
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
+ context "give a config without stale_on_error" do
163
+ context "uses the default value" do
164
+ it "returns cached stale" do
165
+ expect(gateway.get(resource_path)).to eql "cached response"
166
+ end
162
167
  end
163
168
  end
164
169
 
165
170
  context "when stale_on_error configuration is false" do
166
171
  let :gateway do
167
172
  config_with_stale_on_error = config.dup
168
- config_with_stale_on_error.stale_on_error = false
173
+ allow(config_with_stale_on_error).to receive(:stale_on_error).and_return(false)
169
174
  ContentGateway::Gateway.new "API XPTO", config_with_stale_on_error, url_generator, headers: headers
170
175
  end
171
176
 
172
- it "should raise error" do
177
+ it "raises error" do
173
178
  expect { gateway.get resource_path }.to raise_error ContentGateway::ServerError
174
179
  end
175
180
  end
@@ -2,6 +2,9 @@ ENV['RACK_ENV'] = 'test'
2
2
 
3
3
  $:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
4
4
 
5
+ require 'coveralls'
6
+ Coveralls.wear!
7
+
5
8
  require 'byebug'
6
9
  require 'rspec'
7
10
  require 'content_gateway'
@@ -53,21 +53,23 @@ describe ContentGateway::Gateway do
53
53
 
54
54
  describe "Without url generator" do
55
55
  describe "GET method" do
56
+ let(:query_string) { { a: 1, b: 2 } }
57
+
56
58
  before do
57
59
  expect(ContentGateway::Request).
58
60
  to receive(:new).
59
- with(:get, fullpath, headers, nil, config.proxy, cache_params).
61
+ with(:get, fullpath, headers, nil, config.proxy, cache_params.merge(query_string)).
60
62
  and_return(request)
61
63
 
62
64
  expect(ContentGateway::Cache).
63
65
  to receive(:new).
64
- with(config, fullpath, :get, cache_params).
66
+ with(config, fullpath, :get, cache_params.merge(query_string)).
65
67
  and_return(cache)
66
68
  end
67
69
 
68
70
  describe "#get" do
69
71
  it "should do a get request passing the correct parameters" do
70
- expect(gateway_without_url_generator.get(fullpath, cache_params.merge(headers: headers))).to eql data
72
+ expect(gateway_without_url_generator.get(fullpath, cache_params.merge(query_string).merge(headers: headers))).to eql data
71
73
  end
72
74
  end
73
75
  end
@@ -156,7 +156,7 @@ describe ContentGateway::Request do
156
156
 
157
157
  context "when request fails" do
158
158
  it "should return ssl failure error if certificate was not found" do
159
- expect { subject_ssl.execute }.to raise_error(ContentGateway::OpenSSLFailure).with_message("/url - No such file or directory - test")
159
+ expect { subject_ssl.execute }.to raise_error(ContentGateway::OpenSSLFailure).with_message(/^\/url - No such file or directory/)
160
160
  end
161
161
 
162
162
  it "should return ssl failure error if certificate cert was not valid" do
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.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Túlio Ornelas
@@ -14,90 +14,104 @@ authors:
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
- date: 2015-11-19 00:00:00.000000000 Z
17
+ date: 2016-12-19 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: activesupport
21
21
  requirement: !ruby/object:Gem::Requirement
22
22
  requirements:
23
- - - '>='
23
+ - - ">="
24
24
  - !ruby/object:Gem::Version
25
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
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
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
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
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
60
  version: '1.0'
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: rspec
63
63
  requirement: !ruby/object:Gem::Requirement
64
64
  requirements:
65
- - - '>='
65
+ - - ">="
66
66
  - !ruby/object:Gem::Version
67
67
  version: 2.3.0
68
68
  type: :development
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
- - - '>='
72
+ - - ">="
73
73
  - !ruby/object:Gem::Version
74
74
  version: 2.3.0
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: simplecov
77
77
  requirement: !ruby/object:Gem::Requirement
78
78
  requirements:
79
- - - '>='
79
+ - - ">="
80
80
  - !ruby/object:Gem::Version
81
81
  version: 0.7.1
82
82
  type: :development
83
83
  prerelease: false
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
- - - '>='
86
+ - - ">="
87
87
  - !ruby/object:Gem::Version
88
88
  version: 0.7.1
89
89
  - !ruby/object:Gem::Dependency
90
90
  name: byebug
91
91
  requirement: !ruby/object:Gem::Requirement
92
92
  requirements:
93
- - - '>='
93
+ - - ">="
94
94
  - !ruby/object:Gem::Version
95
95
  version: '0'
96
96
  type: :development
97
97
  prerelease: false
98
98
  version_requirements: !ruby/object:Gem::Requirement
99
99
  requirements:
100
- - - '>='
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: rake
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
101
115
  - !ruby/object:Gem::Version
102
116
  version: '0'
103
117
  description: An easy way to get external content with two cache levels. The first
@@ -114,10 +128,11 @@ executables: []
114
128
  extensions: []
115
129
  extra_rdoc_files: []
116
130
  files:
117
- - .gitignore
118
- - .rspec
119
- - .ruby-gemset
120
- - .ruby-version
131
+ - ".gitignore"
132
+ - ".rspec"
133
+ - ".ruby-gemset"
134
+ - ".ruby-version"
135
+ - ".travis.yml"
121
136
  - Changelog
122
137
  - Gemfile
123
138
  - Gemfile.lock
@@ -145,17 +160,17 @@ require_paths:
145
160
  - lib
146
161
  required_ruby_version: !ruby/object:Gem::Requirement
147
162
  requirements:
148
- - - '>='
163
+ - - ">="
149
164
  - !ruby/object:Gem::Version
150
165
  version: '0'
151
166
  required_rubygems_version: !ruby/object:Gem::Requirement
152
167
  requirements:
153
- - - '>='
168
+ - - ">="
154
169
  - !ruby/object:Gem::Version
155
170
  version: '0'
156
171
  requirements: []
157
172
  rubyforge_project:
158
- rubygems_version: 2.4.6
173
+ rubygems_version: 2.5.2
159
174
  signing_key:
160
175
  specification_version: 4
161
176
  summary: Content Gateway