content_gateway 0.2.0 → 0.2.1
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 +4 -0
- data/lib/content_gateway/gateway.rb +63 -12
- data/lib/content_gateway/version.rb +1 -1
- data/spec/integration/content_gateway/gateway_spec.rb +15 -15
- data/spec/unit/content_gateway/gateway_spec.rb +13 -8
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85901cee0dfecc54b74a60365e9edf1dfe7bf5b5
|
4
|
+
data.tar.gz: 331f4a25895c2e6a4cb58ea8db3cba631655efa6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47240429d16d7908ec2bb106ff39eb2928bfa0f5ec57cd741ff16cb8e049011f3c459916699e14daa1d0f1cb462e074461104fed5c0188e1cc580ca9b1b147cf
|
7
|
+
data.tar.gz: 28e5febf0e1ebeafc0218e5e7c14a54b0d2c9dc4b79d61a9f53380e821b446d69b37c47baa18039a7149cc535df48b5e9de251673cb58443281a14236405a415
|
data/Changelog
CHANGED
@@ -8,11 +8,8 @@ module ContentGateway
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def get(resource_path, params = {})
|
11
|
-
|
12
|
-
|
13
|
-
stale_expires_in = params.delete :stale_expires_in
|
14
|
-
skip_cache = params.delete :skip_cache
|
15
|
-
headers = (params.delete :headers) || @default_params[:headers]
|
11
|
+
aux_params = remove_aux_parameters! params
|
12
|
+
headers = aux_params.delete :headers
|
16
13
|
|
17
14
|
url = self.generate_url(resource_path, params)
|
18
15
|
|
@@ -20,35 +17,73 @@ module ContentGateway
|
|
20
17
|
data = { method: :get, url: url }.tap do |h|
|
21
18
|
h[:headers] = headers if headers.present?
|
22
19
|
end
|
23
|
-
|
20
|
+
|
21
|
+
request_params = aux_params.merge(params)
|
24
22
|
send_request(data, request_params)
|
25
23
|
end
|
26
24
|
end
|
27
25
|
|
28
26
|
def post(resource_path, params = {})
|
29
|
-
|
27
|
+
aux_params = remove_aux_parameters! params
|
28
|
+
headers = aux_params.delete :headers
|
29
|
+
payload = aux_params.delete :payload
|
30
|
+
timeout = aux_params.delete :timeout
|
31
|
+
ssl_certificate = aux_params.delete :ssl_certificate
|
32
|
+
|
30
33
|
url = self.generate_url(resource_path, params)
|
31
34
|
|
32
35
|
measure("POST - #{url}") do
|
33
|
-
|
36
|
+
data = { method: :post, url: url, payload: payload }.tap do |h|
|
37
|
+
h[:headers] = headers if headers.present?
|
38
|
+
end
|
39
|
+
|
40
|
+
request_params = { timeout: timeout }.merge(params).tap do |h|
|
41
|
+
h[:ssl_certificate] = ssl_certificate unless ssl_certificate.nil?
|
42
|
+
end
|
43
|
+
send_request(data, request_params)
|
34
44
|
end
|
35
45
|
end
|
36
46
|
|
37
47
|
def put(resource_path, params = {})
|
38
|
-
|
48
|
+
aux_params = remove_aux_parameters! params
|
49
|
+
headers = aux_params.delete :headers
|
50
|
+
payload = aux_params.delete :payload
|
51
|
+
timeout = aux_params.delete :timeout
|
52
|
+
ssl_certificate = aux_params.delete :ssl_certificate
|
53
|
+
|
39
54
|
url = self.generate_url(resource_path, params)
|
40
55
|
|
41
56
|
measure("PUT - #{url}") do
|
42
|
-
|
57
|
+
data = { method: :put, url: url, payload: payload }.tap do |h|
|
58
|
+
h[:headers] = headers if headers.present?
|
59
|
+
end
|
60
|
+
|
61
|
+
request_params = { timeout: timeout }.merge(params).tap do |h|
|
62
|
+
h[:ssl_certificate] = ssl_certificate unless ssl_certificate.nil?
|
63
|
+
end
|
64
|
+
|
65
|
+
send_request(data, request_params)
|
43
66
|
end
|
44
67
|
end
|
45
68
|
|
46
69
|
def delete(resource_path, params = {})
|
47
|
-
|
70
|
+
aux_params = remove_aux_parameters! params
|
71
|
+
headers = aux_params.delete :headers
|
72
|
+
timeout = aux_params.delete :timeout
|
73
|
+
ssl_certificate = aux_params.delete :ssl_certificate
|
74
|
+
|
48
75
|
url = self.generate_url(resource_path, params)
|
49
76
|
|
50
77
|
measure("DELETE - #{url}") do
|
51
|
-
|
78
|
+
data = { method: :delete, url: url }.tap do |h|
|
79
|
+
h[:headers] = headers if headers.present?
|
80
|
+
end
|
81
|
+
|
82
|
+
request_params = { timeout: timeout }.tap do |h|
|
83
|
+
h[:ssl_certificate] = ssl_certificate unless ssl_certificate.nil?
|
84
|
+
end
|
85
|
+
|
86
|
+
send_request(data, request_params)
|
52
87
|
end
|
53
88
|
end
|
54
89
|
|
@@ -74,6 +109,22 @@ module ContentGateway
|
|
74
109
|
|
75
110
|
private
|
76
111
|
|
112
|
+
def remove_aux_parameters! params
|
113
|
+
aux_params = params.select do |k, v|
|
114
|
+
[:timeout, :expires_in, :stale_expires_in, :skip_cache, :headers, :payload, :ssl_certificate].include? k
|
115
|
+
end
|
116
|
+
|
117
|
+
aux_params.tap do |p|
|
118
|
+
p[:headers] = p[:headers] || @default_params[:headers]
|
119
|
+
end
|
120
|
+
|
121
|
+
params.delete_if do |k,v|
|
122
|
+
aux_params.keys.include? k
|
123
|
+
end
|
124
|
+
|
125
|
+
aux_params
|
126
|
+
end
|
127
|
+
|
77
128
|
def send_request(request_data, params = {})
|
78
129
|
method = request_data[:method] || :get
|
79
130
|
url = request_data[:url]
|
@@ -290,27 +290,27 @@ describe ContentGateway::Gateway do
|
|
290
290
|
end
|
291
291
|
|
292
292
|
it "should do request with http post" do
|
293
|
-
stub_request(method: :post, url: resource_url, proxy: config.proxy, payload: payload)
|
293
|
+
stub_request(method: :post, url: resource_url, proxy: config.proxy, payload: payload, headers: headers)
|
294
294
|
gateway.post resource_path, payload: payload
|
295
295
|
end
|
296
296
|
|
297
297
|
it "should raise NotFound exception on 404 error" do
|
298
|
-
stub_request_with_error({ method: :post, url: resource_url, proxy: config.proxy, payload: payload }, RestClient::ResourceNotFound.new)
|
298
|
+
stub_request_with_error({ method: :post, url: resource_url, proxy: config.proxy, payload: payload, headers: headers }, RestClient::ResourceNotFound.new)
|
299
299
|
expect { gateway.post resource_path, payload: payload }.to raise_error ContentGateway::ResourceNotFound
|
300
300
|
end
|
301
301
|
|
302
302
|
it "should raise UnprocessableEntity exception on 401 error" do
|
303
|
-
stub_request_with_error({ method: :post, url: resource_url, proxy: config.proxy, payload: payload }, RestClient::Unauthorized.new)
|
303
|
+
stub_request_with_error({ method: :post, url: resource_url, proxy: config.proxy, payload: payload, headers: headers }, RestClient::Unauthorized.new)
|
304
304
|
expect { gateway.post resource_path, payload: payload }.to raise_error(ContentGateway::UnauthorizedError)
|
305
305
|
end
|
306
306
|
|
307
307
|
it "should raise Forbidden exception on 403 error" do
|
308
|
-
stub_request_with_error({ method: :post, url: resource_url, proxy: config.proxy, payload: payload }, RestClient::Forbidden.new)
|
308
|
+
stub_request_with_error({ method: :post, url: resource_url, proxy: config.proxy, payload: payload, headers: headers }, RestClient::Forbidden.new)
|
309
309
|
expect { gateway.post resource_path, payload: payload }.to raise_error(ContentGateway::Forbidden)
|
310
310
|
end
|
311
311
|
|
312
312
|
it "should raise ConnectionFailure exception on 500 error" do
|
313
|
-
stub_request_with_error({ method: :post, url: resource_url, proxy: config.proxy, payload: payload }, SocketError.new)
|
313
|
+
stub_request_with_error({ method: :post, url: resource_url, proxy: config.proxy, payload: payload, headers: headers }, SocketError.new)
|
314
314
|
expect { gateway.post resource_path, payload: payload }.to raise_error ContentGateway::ConnectionFailure
|
315
315
|
end
|
316
316
|
end
|
@@ -325,27 +325,27 @@ describe ContentGateway::Gateway do
|
|
325
325
|
end
|
326
326
|
|
327
327
|
it "should do request with http post" do
|
328
|
-
stub_request(method: :delete, url: resource_url, proxy: config.proxy,
|
328
|
+
stub_request(method: :delete, url: resource_url, proxy: config.proxy, headers: headers)
|
329
329
|
gateway.delete resource_path, payload: payload
|
330
330
|
end
|
331
331
|
|
332
332
|
it "should raise NotFound exception on 404 error" do
|
333
|
-
stub_request_with_error({ method: :delete, url: resource_url, proxy: config.proxy,
|
333
|
+
stub_request_with_error({ method: :delete, url: resource_url, proxy: config.proxy, headers: headers }, RestClient::ResourceNotFound.new)
|
334
334
|
expect { gateway.delete resource_path, payload: payload }.to raise_error ContentGateway::ResourceNotFound
|
335
335
|
end
|
336
336
|
|
337
337
|
it "should raise UnprocessableEntity exception on 401 error" do
|
338
|
-
stub_request_with_error({ method: :delete, url: resource_url, proxy: config.proxy,
|
338
|
+
stub_request_with_error({ method: :delete, url: resource_url, proxy: config.proxy, headers: headers }, RestClient::Unauthorized.new)
|
339
339
|
expect { gateway.delete resource_path, payload: payload }.to raise_error(ContentGateway::UnauthorizedError)
|
340
340
|
end
|
341
341
|
|
342
342
|
it "should raise Forbidden exception on 403 error" do
|
343
|
-
stub_request_with_error({ method: :delete, url: resource_url, proxy: config.proxy,
|
343
|
+
stub_request_with_error({ method: :delete, url: resource_url, proxy: config.proxy, headers: headers }, RestClient::Forbidden.new)
|
344
344
|
expect { gateway.delete resource_path, payload: payload }.to raise_error(ContentGateway::Forbidden)
|
345
345
|
end
|
346
346
|
|
347
347
|
it "should raise ConnectionFailure exception on 500 error" do
|
348
|
-
stub_request_with_error({ method: :delete, url: resource_url, proxy: config.proxy,
|
348
|
+
stub_request_with_error({ method: :delete, url: resource_url, proxy: config.proxy, headers: headers }, SocketError.new)
|
349
349
|
expect { gateway.delete resource_path, payload: payload }.to raise_error ContentGateway::ConnectionFailure
|
350
350
|
end
|
351
351
|
end
|
@@ -360,27 +360,27 @@ describe ContentGateway::Gateway do
|
|
360
360
|
end
|
361
361
|
|
362
362
|
it "should do request with http put" do
|
363
|
-
stub_request(method: :put, url: resource_url, proxy: config.proxy, payload: payload)
|
363
|
+
stub_request(method: :put, url: resource_url, proxy: config.proxy, payload: payload, headers: headers)
|
364
364
|
gateway.put resource_path, payload: payload
|
365
365
|
end
|
366
366
|
|
367
367
|
it "should raise NotFound exception on 404 error" do
|
368
|
-
stub_request_with_error({ method: :put, url: resource_url, proxy: config.proxy, payload: payload }, RestClient::ResourceNotFound.new)
|
368
|
+
stub_request_with_error({ method: :put, url: resource_url, proxy: config.proxy, payload: payload, headers: headers }, RestClient::ResourceNotFound.new)
|
369
369
|
expect { gateway.put resource_path, payload: payload }.to raise_error ContentGateway::ResourceNotFound
|
370
370
|
end
|
371
371
|
|
372
372
|
it "should raise UnprocessableEntity exception on 422 error" do
|
373
|
-
stub_request_with_error({ method: :put, url: resource_url, proxy: config.proxy, payload: payload }, RestClient::UnprocessableEntity)
|
373
|
+
stub_request_with_error({ method: :put, url: resource_url, proxy: config.proxy, payload: payload, headers: headers }, RestClient::UnprocessableEntity)
|
374
374
|
expect { gateway.put resource_path, payload: payload }.to raise_error ContentGateway::ValidationError
|
375
375
|
end
|
376
376
|
|
377
377
|
it "should raise Forbidden exception on 403 error" do
|
378
|
-
stub_request_with_error({ method: :put, url: resource_url, proxy: config.proxy, payload: payload }, RestClient::Forbidden.new)
|
378
|
+
stub_request_with_error({ method: :put, url: resource_url, proxy: config.proxy, payload: payload, headers: headers }, RestClient::Forbidden.new)
|
379
379
|
expect { gateway.put resource_path, payload: payload }.to raise_error(ContentGateway::Forbidden)
|
380
380
|
end
|
381
381
|
|
382
382
|
it "should raise ConnectionFailure exception on 500 error" do
|
383
|
-
stub_request_with_error({ method: :put, url: resource_url, proxy: config.proxy, payload: payload }, SocketError.new)
|
383
|
+
stub_request_with_error({ method: :put, url: resource_url, proxy: config.proxy, payload: payload, headers: headers }, SocketError.new)
|
384
384
|
expect { gateway.put resource_path, payload: payload }.to raise_error ContentGateway::ConnectionFailure
|
385
385
|
end
|
386
386
|
end
|
@@ -13,10 +13,15 @@ describe ContentGateway::Gateway do
|
|
13
13
|
let(:cache) { double("cache", use?: false, status: "HIT") }
|
14
14
|
let(:request) { double("request", execute: data) }
|
15
15
|
let(:data) { '{"param": "value"}' }
|
16
|
-
let(:cache_params) { { timeout: 2, expires_in: 30, stale_expires_in: 180, skip_cache: false } }
|
16
|
+
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"} } }
|
17
|
+
let(:connection_params) {{ timeout: 2, ssl_certificate: {ssl_client_cert: "test", ssl_client_key: "test"} }}
|
17
18
|
|
18
19
|
before do
|
19
|
-
allow(
|
20
|
+
allow(File).to receive(:read).with("test").and_return("cert_content")
|
21
|
+
allow(OpenSSL::X509::Certificate).to receive(:new).with("cert_content").and_return("cert")
|
22
|
+
allow(OpenSSL::PKey::RSA).to receive(:new).with("cert_content").and_return("key")
|
23
|
+
|
24
|
+
expect(url_generator).to receive(:generate).with(path, {}).and_return("url")
|
20
25
|
end
|
21
26
|
|
22
27
|
describe "GET method" do
|
@@ -48,11 +53,11 @@ describe ContentGateway::Gateway do
|
|
48
53
|
before do
|
49
54
|
expect(ContentGateway::Request).
|
50
55
|
to receive(:new).
|
51
|
-
with(:post, "url", nil, payload, config.proxy,
|
56
|
+
with(:post, "url", nil, payload, config.proxy, connection_params).
|
52
57
|
and_return(request)
|
53
58
|
expect(ContentGateway::Cache).
|
54
59
|
to receive(:new).
|
55
|
-
with(config, "url", :post,
|
60
|
+
with(config, "url", :post, connection_params).
|
56
61
|
and_return(cache)
|
57
62
|
end
|
58
63
|
|
@@ -73,11 +78,11 @@ describe ContentGateway::Gateway do
|
|
73
78
|
before do
|
74
79
|
expect(ContentGateway::Request).
|
75
80
|
to receive(:new).
|
76
|
-
with(:put, "url", nil, payload, config.proxy,
|
81
|
+
with(:put, "url", nil, payload, config.proxy, connection_params).
|
77
82
|
and_return(request)
|
78
83
|
expect(ContentGateway::Cache).
|
79
84
|
to receive(:new).
|
80
|
-
with(config, "url", :put,
|
85
|
+
with(config, "url", :put, connection_params).
|
81
86
|
and_return(cache)
|
82
87
|
end
|
83
88
|
|
@@ -98,11 +103,11 @@ describe ContentGateway::Gateway do
|
|
98
103
|
before do
|
99
104
|
expect(ContentGateway::Request).
|
100
105
|
to receive(:new).
|
101
|
-
with(:delete, "url", nil,
|
106
|
+
with(:delete, "url", nil, nil, config.proxy, connection_params).
|
102
107
|
and_return(request)
|
103
108
|
expect(ContentGateway::Cache).
|
104
109
|
to receive(:new).
|
105
|
-
with(config, "url", :delete,
|
110
|
+
with(config, "url", :delete, connection_params).
|
106
111
|
and_return(cache)
|
107
112
|
end
|
108
113
|
|
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.2.
|
4
|
+
version: 0.2.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: 2014-
|
17
|
+
date: 2014-11-06 00:00:00.000000000 Z
|
18
18
|
dependencies:
|
19
19
|
- !ruby/object:Gem::Dependency
|
20
20
|
name: activesupport
|
@@ -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.
|
158
|
+
rubygems_version: 2.2.2
|
159
159
|
signing_key:
|
160
160
|
specification_version: 4
|
161
161
|
summary: Content Gateway
|