content_gateway 0.4.0 → 0.5.0
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/Changelog +7 -0
- data/Gemfile.lock +16 -15
- data/lib/content_gateway/exceptions.rb +2 -0
- data/lib/content_gateway/gateway.rb +11 -4
- data/lib/content_gateway/version.rb +1 -1
- data/spec/unit/content_gateway/gateway_spec.rb +93 -89
- 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: ee3e2f6da92f839d6d66363fb6860fe51ca61ff1
|
4
|
+
data.tar.gz: 25fcaa57e51bf4f365133c4d5672ce93cb1076e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e95aa8acf647aaa56102fcc5e28ca6fab2f46d0885d3353d9f785003f6a4848d6ee367cbbc2d79a7ef78679e20f0f296d51f2e889ef29dc4515a6d8e21a2db5
|
7
|
+
data.tar.gz: 79995262957697314650059639726c15d474a199c59c9f96ee377ceadaa9b2c38a0ebbc930c5eededd0ded68f8908112419a9b0ef985919581b2c48389270881
|
data/Changelog
CHANGED
@@ -1,10 +1,17 @@
|
|
1
|
+
2015-07-24 [0.5.0]
|
2
|
+
|
3
|
+
* Mapping JSON parse errors to ContentGateway::ParserError
|
4
|
+
|
1
5
|
2015-06-16 [0.4.0]
|
6
|
+
|
2
7
|
* Adding ssl_version support to ssl_certificate hash
|
3
8
|
|
4
9
|
2015-01-05 [0.3.0]
|
10
|
+
|
5
11
|
* Optional url generator. (Without the url generator on boot the content gateway will use the get/post/delete/put resource argument as full url for request). Closes #4
|
6
12
|
|
7
13
|
2014-11-06 [0.2.1]
|
14
|
+
|
8
15
|
* Fix: Do not send connection parameters to url generator. Closes #2
|
9
16
|
* Fix: Send http headers to request object. Closes #3
|
10
17
|
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
content_gateway (0.
|
4
|
+
content_gateway (0.5.0)
|
5
5
|
activesupport
|
6
6
|
json
|
7
7
|
rest-client
|
@@ -9,13 +9,12 @@ PATH
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
-
activesupport (4.
|
13
|
-
i18n (~> 0.6, >= 0.6.
|
14
|
-
|
15
|
-
|
12
|
+
activesupport (4.1.8)
|
13
|
+
i18n (~> 0.6, >= 0.6.9)
|
14
|
+
json (~> 1.7, >= 1.7.7)
|
15
|
+
minitest (~> 5.1)
|
16
16
|
thread_safe (~> 0.1)
|
17
|
-
tzinfo (~>
|
18
|
-
atomic (1.1.14)
|
17
|
+
tzinfo (~> 1.1)
|
19
18
|
byebug (3.5.1)
|
20
19
|
columnize (~> 0.8)
|
21
20
|
debugger-linecache (~> 1.2)
|
@@ -23,13 +22,15 @@ GEM
|
|
23
22
|
columnize (0.8.9)
|
24
23
|
debugger-linecache (1.2.0)
|
25
24
|
diff-lcs (1.2.5)
|
26
|
-
i18n (0.6.
|
25
|
+
i18n (0.6.11)
|
27
26
|
json (1.8.1)
|
28
|
-
mime-types (2.
|
29
|
-
minitest (
|
27
|
+
mime-types (2.4.3)
|
28
|
+
minitest (5.5.0)
|
30
29
|
multi_json (1.7.9)
|
31
|
-
|
32
|
-
|
30
|
+
netrc (0.10.2)
|
31
|
+
rest-client (1.7.2)
|
32
|
+
mime-types (>= 1.16, < 3.0)
|
33
|
+
netrc (~> 0.7)
|
33
34
|
rspec (3.1.0)
|
34
35
|
rspec-core (~> 3.1.0)
|
35
36
|
rspec-expectations (~> 3.1.0)
|
@@ -47,9 +48,9 @@ GEM
|
|
47
48
|
simplecov-html (~> 0.7.1)
|
48
49
|
simplecov-html (0.7.1)
|
49
50
|
slop (3.6.0)
|
50
|
-
thread_safe (0.
|
51
|
-
|
52
|
-
|
51
|
+
thread_safe (0.3.4)
|
52
|
+
tzinfo (1.2.2)
|
53
|
+
thread_safe (~> 0.1)
|
53
54
|
|
54
55
|
PLATFORMS
|
55
56
|
ruby
|
@@ -88,19 +88,19 @@ module ContentGateway
|
|
88
88
|
end
|
89
89
|
|
90
90
|
def get_json(resource_path, params = {})
|
91
|
-
|
91
|
+
json_request(:get, resource_path, params)
|
92
92
|
end
|
93
93
|
|
94
94
|
def post_json(resource_path, params = {})
|
95
|
-
|
95
|
+
json_request(:post, resource_path, params)
|
96
96
|
end
|
97
97
|
|
98
98
|
def put_json(resource_path, params = {})
|
99
|
-
|
99
|
+
json_request(:put, resource_path, params)
|
100
100
|
end
|
101
101
|
|
102
102
|
def delete_json(resource_path, params = {})
|
103
|
-
|
103
|
+
json_request(:delete, resource_path, params)
|
104
104
|
end
|
105
105
|
|
106
106
|
def generate_url(resource_path, params = {})
|
@@ -158,6 +158,13 @@ module ContentGateway
|
|
158
158
|
end
|
159
159
|
end
|
160
160
|
|
161
|
+
def json_request(verb, resource_path, params = {})
|
162
|
+
JSON.parse(self.send(verb, resource_path, params))
|
163
|
+
rescue JSON::ParserError => e
|
164
|
+
url = generate_url(resource_path, params) rescue resource_path
|
165
|
+
raise ContentGateway::ParserError.new(url, e)
|
166
|
+
end
|
167
|
+
|
161
168
|
def measure(message)
|
162
169
|
result = nil
|
163
170
|
time_elapsed = Benchmark.measure { result = yield }
|
@@ -18,6 +18,7 @@ describe ContentGateway::Gateway do
|
|
18
18
|
let(:cache) { double("cache", use?: false, status: "HIT") }
|
19
19
|
let(:request) { double("request", execute: data) }
|
20
20
|
let(:data) { '{"param": "value"}' }
|
21
|
+
let(:invalid_data) { "" }
|
21
22
|
let(:cache_params) { { timeout: 2, expires_in: 30, stale_expires_in: 180, skip_cache: false, ssl_certificate: {ssl_client_cert: "test", ssl_client_key: "test"} } }
|
22
23
|
let(:connection_params) {{ timeout: 2, ssl_certificate: {ssl_client_cert: "test", ssl_client_key: "test"} }}
|
23
24
|
|
@@ -27,17 +28,41 @@ describe ContentGateway::Gateway do
|
|
27
28
|
allow(OpenSSL::PKey::RSA).to receive(:new).with("cert_content").and_return("key")
|
28
29
|
end
|
29
30
|
|
31
|
+
shared_examples "request" do
|
32
|
+
describe "doing a request" do
|
33
|
+
it "should do a # {verb} request passing the correct parameters" do
|
34
|
+
expect(subject.send(verb, path, params)).to eql data
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "doing a json request" do
|
39
|
+
it "should parse the response as JSON" do
|
40
|
+
expect(subject.send("#{verb}_json", path, params)).to eql JSON.parse(data)
|
41
|
+
end
|
42
|
+
|
43
|
+
context "when the answer is not a valid JSON" do
|
44
|
+
let(:data) { invalid_data }
|
45
|
+
|
46
|
+
it "should raise ContentGateway::ParserError" do
|
47
|
+
expect { subject.send("#{verb}_json", path, params) }.
|
48
|
+
to raise_error(ContentGateway::ParserError)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
30
54
|
describe "Without url generator" do
|
31
55
|
describe "GET method" do
|
32
56
|
before do
|
33
57
|
expect(ContentGateway::Request).
|
34
|
-
|
35
|
-
|
36
|
-
|
58
|
+
to receive(:new).
|
59
|
+
with(:get, fullpath, headers, nil, config.proxy, cache_params).
|
60
|
+
and_return(request)
|
61
|
+
|
37
62
|
expect(ContentGateway::Cache).
|
38
|
-
|
39
|
-
|
40
|
-
|
63
|
+
to receive(:new).
|
64
|
+
with(config, fullpath, :get, cache_params).
|
65
|
+
and_return(cache)
|
41
66
|
end
|
42
67
|
|
43
68
|
describe "#get" do
|
@@ -50,13 +75,14 @@ describe ContentGateway::Gateway do
|
|
50
75
|
describe "POST method" do
|
51
76
|
before do
|
52
77
|
expect(ContentGateway::Request).
|
53
|
-
|
54
|
-
|
55
|
-
|
78
|
+
to receive(:new).
|
79
|
+
with(:post, fullpath, nil, payload, config.proxy, connection_params).
|
80
|
+
and_return(request)
|
81
|
+
|
56
82
|
expect(ContentGateway::Cache).
|
57
|
-
|
58
|
-
|
59
|
-
|
83
|
+
to receive(:new).
|
84
|
+
with(config, fullpath, :post, connection_params).
|
85
|
+
and_return(cache)
|
60
86
|
end
|
61
87
|
|
62
88
|
describe "#post" do
|
@@ -69,13 +95,14 @@ describe ContentGateway::Gateway do
|
|
69
95
|
describe "PUT method" do
|
70
96
|
before do
|
71
97
|
expect(ContentGateway::Request).
|
72
|
-
|
73
|
-
|
74
|
-
|
98
|
+
to receive(:new).
|
99
|
+
with(:put, fullpath, nil, payload, config.proxy, connection_params).
|
100
|
+
and_return(request)
|
101
|
+
|
75
102
|
expect(ContentGateway::Cache).
|
76
|
-
|
77
|
-
|
78
|
-
|
103
|
+
to receive(:new).
|
104
|
+
with(config, fullpath, :put, connection_params).
|
105
|
+
and_return(cache)
|
79
106
|
end
|
80
107
|
|
81
108
|
describe "#put" do
|
@@ -88,13 +115,14 @@ describe ContentGateway::Gateway do
|
|
88
115
|
describe "DELETE method" do
|
89
116
|
before do
|
90
117
|
expect(ContentGateway::Request).
|
91
|
-
|
92
|
-
|
93
|
-
|
118
|
+
to receive(:new).
|
119
|
+
with(:delete, fullpath, nil, nil, config.proxy, connection_params).
|
120
|
+
and_return(request)
|
121
|
+
|
94
122
|
expect(ContentGateway::Cache).
|
95
|
-
|
96
|
-
|
97
|
-
|
123
|
+
to receive(:new).
|
124
|
+
with(config, fullpath, :delete, connection_params).
|
125
|
+
and_return(cache)
|
98
126
|
end
|
99
127
|
|
100
128
|
describe "#delete" do
|
@@ -107,106 +135,82 @@ describe ContentGateway::Gateway do
|
|
107
135
|
|
108
136
|
describe "With url generator" do
|
109
137
|
before do
|
110
|
-
expect(url_generator).to receive(:generate).with(path, {}).and_return("url")
|
138
|
+
expect(url_generator).to receive(:generate).at_least(:once).with(path, {}).and_return("url")
|
111
139
|
end
|
112
140
|
|
113
141
|
describe "GET method" do
|
114
142
|
before do
|
115
143
|
expect(ContentGateway::Request).
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
expect(ContentGateway::Cache).
|
120
|
-
to receive(:new).
|
121
|
-
with(config, "url", :get, cache_params).
|
122
|
-
and_return(cache)
|
123
|
-
end
|
144
|
+
to receive(:new).
|
145
|
+
with(:get, "url", headers, nil, config.proxy, cache_params).
|
146
|
+
and_return(request)
|
124
147
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
148
|
+
expect(ContentGateway::Cache).
|
149
|
+
to receive(:new).
|
150
|
+
with(config, "url", :get, cache_params).
|
151
|
+
and_return(cache)
|
129
152
|
end
|
130
153
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
end
|
154
|
+
it_should_behave_like "request" do
|
155
|
+
let(:verb) { "get" }
|
156
|
+
let(:params) { cache_params.merge(headers: headers) }
|
135
157
|
end
|
136
158
|
end
|
137
159
|
|
138
160
|
describe "POST method" do
|
139
161
|
before do
|
140
162
|
expect(ContentGateway::Request).
|
141
|
-
|
142
|
-
|
143
|
-
|
163
|
+
to receive(:new).
|
164
|
+
with(:post, "url", nil, payload, config.proxy, connection_params).
|
165
|
+
and_return(request)
|
166
|
+
|
144
167
|
expect(ContentGateway::Cache).
|
145
|
-
|
146
|
-
|
147
|
-
|
168
|
+
to receive(:new).
|
169
|
+
with(config, "url", :post, connection_params).
|
170
|
+
and_return(cache)
|
148
171
|
end
|
149
172
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
describe "#post_json" do
|
157
|
-
it "should parse the response as JSON" do
|
158
|
-
expect(subject.post_json(path, cache_params.merge(payload: payload))).to eql JSON.parse(data)
|
159
|
-
end
|
173
|
+
it_should_behave_like "request" do
|
174
|
+
let(:verb) { "post" }
|
175
|
+
let(:params) { cache_params.merge(payload: payload) }
|
160
176
|
end
|
161
177
|
end
|
162
178
|
|
163
179
|
describe "PUT method" do
|
164
180
|
before do
|
165
181
|
expect(ContentGateway::Request).
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
expect(ContentGateway::Cache).
|
170
|
-
to receive(:new).
|
171
|
-
with(config, "url", :put, connection_params).
|
172
|
-
and_return(cache)
|
173
|
-
end
|
182
|
+
to receive(:new).
|
183
|
+
with(:put, "url", nil, payload, config.proxy, connection_params).
|
184
|
+
and_return(request)
|
174
185
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
186
|
+
expect(ContentGateway::Cache).
|
187
|
+
to receive(:new).
|
188
|
+
with(config, "url", :put, connection_params).
|
189
|
+
and_return(cache)
|
179
190
|
end
|
180
191
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
end
|
192
|
+
it_should_behave_like "request" do
|
193
|
+
let(:verb) { "put" }
|
194
|
+
let(:params) { cache_params.merge(payload: payload) }
|
185
195
|
end
|
186
196
|
end
|
187
197
|
|
188
198
|
describe "DELETE method" do
|
189
199
|
before do
|
190
200
|
expect(ContentGateway::Request).
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
expect(ContentGateway::Cache).
|
195
|
-
to receive(:new).
|
196
|
-
with(config, "url", :delete, connection_params).
|
197
|
-
and_return(cache)
|
198
|
-
end
|
201
|
+
to receive(:new).
|
202
|
+
with(:delete, "url", nil, nil, config.proxy, connection_params).
|
203
|
+
and_return(request)
|
199
204
|
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
205
|
+
expect(ContentGateway::Cache).
|
206
|
+
to receive(:new).
|
207
|
+
with(config, "url", :delete, connection_params).
|
208
|
+
and_return(cache)
|
204
209
|
end
|
205
210
|
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
end
|
211
|
+
it_should_behave_like "request" do
|
212
|
+
let(:verb) { "delete" }
|
213
|
+
let(:params) { cache_params.merge(payload: payload) }
|
210
214
|
end
|
211
215
|
end
|
212
216
|
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.
|
4
|
+
version: 0.5.0
|
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-
|
17
|
+
date: 2015-07-24 00:00:00.000000000 Z
|
18
18
|
dependencies:
|
19
19
|
- !ruby/object:Gem::Dependency
|
20
20
|
name: activesupport
|