content_gateway 0.2.1 → 0.3.0

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: 85901cee0dfecc54b74a60365e9edf1dfe7bf5b5
4
- data.tar.gz: 331f4a25895c2e6a4cb58ea8db3cba631655efa6
3
+ metadata.gz: 6496c9d2bb6da6aa267c4650e40fb529bf808cb7
4
+ data.tar.gz: e3b5d86df942e0798184e500b92393b97a177218
5
5
  SHA512:
6
- metadata.gz: 47240429d16d7908ec2bb106ff39eb2928bfa0f5ec57cd741ff16cb8e049011f3c459916699e14daa1d0f1cb462e074461104fed5c0188e1cc580ca9b1b147cf
7
- data.tar.gz: 28e5febf0e1ebeafc0218e5e7c14a54b0d2c9dc4b79d61a9f53380e821b446d69b37c47baa18039a7149cc535df48b5e9de251673cb58443281a14236405a415
6
+ metadata.gz: a592281ea0b05ac5c191f347d5358ae3d2fcf77ee21b1d0a148c3de55f12f90669105839847ee16cd9e706e583ef5f4727060073569a590c25aa50a90354bc6b
7
+ data.tar.gz: cba7bc8d0ef2934debfc73660fdc16e14face3c19fa20964c1f6c63fb4f408e2f76ae4b985aeb167e5bd6bd71f65decef8b53e07420223c15583cdfbb83a3dd4
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- ruby-2.0.0-p481
1
+ ruby-2.0.0-p598
data/Changelog CHANGED
@@ -1,3 +1,6 @@
1
+ 2015-01-05 [0.3.0]
2
+ * 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
3
+
1
4
  2014-11-06 [0.2.1]
2
5
  * Fix: Do not send connection parameters to url generator. Closes #2
3
6
  * Fix: Send http headers to request object. Closes #3
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- content_gateway (0.2.0)
4
+ content_gateway (0.3.0)
5
5
  activesupport
6
6
  json
7
7
  rest-client
@@ -1,6 +1,6 @@
1
1
  module ContentGateway
2
2
  class Gateway
3
- def initialize(label, config, url_generator, default_params = {})
3
+ def initialize(label, config, url_generator = nil, default_params = {})
4
4
  @label = label
5
5
  @config = config
6
6
  @url_generator = url_generator
@@ -104,7 +104,11 @@ module ContentGateway
104
104
  end
105
105
 
106
106
  def generate_url(resource_path, params = {})
107
- @url_generator.generate(resource_path, params)
107
+ if @url_generator.respond_to? :generate
108
+ @url_generator.generate(resource_path, params)
109
+ else
110
+ resource_path
111
+ end
108
112
  end
109
113
 
110
114
  private
@@ -1,3 +1,3 @@
1
1
  module ContentGateway
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -5,11 +5,16 @@ describe ContentGateway::Gateway do
5
5
  ContentGateway::Gateway.new("label", config, url_generator)
6
6
  end
7
7
 
8
+ let(:gateway_without_url_generator) do
9
+ ContentGateway::Gateway.new("label", config)
10
+ end
11
+
8
12
  let(:config) { double("config", proxy: nil) }
9
13
  let(:headers) { { "Content-Type" => "application/json" } }
10
14
  let(:payload) { { "data" => 1234 } }
11
15
  let(:url_generator) { double("URL generator") }
12
16
  let(:path) { "/api/test.json" }
17
+ let(:fullpath) { "www.teste.com/api/test.json" }
13
18
  let(:cache) { double("cache", use?: false, status: "HIT") }
14
19
  let(:request) { double("request", execute: data) }
15
20
  let(:data) { '{"param": "value"}' }
@@ -20,106 +25,188 @@ describe ContentGateway::Gateway do
20
25
  allow(File).to receive(:read).with("test").and_return("cert_content")
21
26
  allow(OpenSSL::X509::Certificate).to receive(:new).with("cert_content").and_return("cert")
22
27
  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")
25
28
  end
26
29
 
27
- describe "GET method" do
28
- before do
29
- expect(ContentGateway::Request).
30
+ describe "Without url generator" do
31
+ describe "GET method" do
32
+ before do
33
+ expect(ContentGateway::Request).
30
34
  to receive(:new).
31
- with(:get, "url", headers, nil, config.proxy, cache_params).
35
+ with(:get, fullpath, headers, nil, config.proxy, cache_params).
32
36
  and_return(request)
33
- expect(ContentGateway::Cache).
37
+ expect(ContentGateway::Cache).
34
38
  to receive(:new).
35
- with(config, "url", :get, cache_params).
39
+ with(config, fullpath, :get, cache_params).
36
40
  and_return(cache)
41
+ end
42
+
43
+ describe "#get" do
44
+ it "should do a get request passing the correct parameters" do
45
+ expect(gateway_without_url_generator.get(fullpath, cache_params.merge(headers: headers))).to eql data
46
+ end
47
+ end
37
48
  end
38
49
 
39
- describe "#get" do
40
- it "should do a get request passing the correct parameters" do
41
- expect(subject.get(path, cache_params.merge(headers: headers))).to eql data
50
+ describe "POST method" do
51
+ before do
52
+ expect(ContentGateway::Request).
53
+ to receive(:new).
54
+ with(:post, fullpath, nil, payload, config.proxy, connection_params).
55
+ and_return(request)
56
+ expect(ContentGateway::Cache).
57
+ to receive(:new).
58
+ with(config, fullpath, :post, connection_params).
59
+ and_return(cache)
60
+ end
61
+
62
+ describe "#post" do
63
+ it "should do a post request passing the correct parameters" do
64
+ expect(gateway_without_url_generator.post(fullpath, cache_params.merge(payload: payload))).to eql data
65
+ end
42
66
  end
43
67
  end
44
68
 
45
- describe "#get_json" do
46
- it "should parse the response as JSON" do
47
- expect(subject.get_json(path, cache_params.merge(headers: headers))).to eql JSON.parse(data)
69
+ describe "PUT method" do
70
+ before do
71
+ expect(ContentGateway::Request).
72
+ to receive(:new).
73
+ with(:put, fullpath, nil, payload, config.proxy, connection_params).
74
+ and_return(request)
75
+ expect(ContentGateway::Cache).
76
+ to receive(:new).
77
+ with(config, fullpath, :put, connection_params).
78
+ and_return(cache)
79
+ end
80
+
81
+ describe "#put" do
82
+ it "should do a put request passing the correct parameters" do
83
+ expect(gateway_without_url_generator.put(fullpath, cache_params.merge(payload: payload))).to eql data
84
+ end
85
+ end
86
+ end
87
+
88
+ describe "DELETE method" do
89
+ before do
90
+ expect(ContentGateway::Request).
91
+ to receive(:new).
92
+ with(:delete, fullpath, nil, nil, config.proxy, connection_params).
93
+ and_return(request)
94
+ expect(ContentGateway::Cache).
95
+ to receive(:new).
96
+ with(config, fullpath, :delete, connection_params).
97
+ and_return(cache)
98
+ end
99
+
100
+ describe "#delete" do
101
+ it "should do a delete request passing the correct parameters" do
102
+ expect(gateway_without_url_generator.delete(fullpath, cache_params.merge(payload: payload))).to eql data
103
+ end
48
104
  end
49
105
  end
50
106
  end
51
107
 
52
- describe "POST method" do
108
+ describe "With url generator" do
53
109
  before do
54
- expect(ContentGateway::Request).
110
+ expect(url_generator).to receive(:generate).with(path, {}).and_return("url")
111
+ end
112
+
113
+ describe "GET method" do
114
+ before do
115
+ expect(ContentGateway::Request).
116
+ to receive(:new).
117
+ with(:get, "url", headers, nil, config.proxy, cache_params).
118
+ and_return(request)
119
+ expect(ContentGateway::Cache).
120
+ to receive(:new).
121
+ with(config, "url", :get, cache_params).
122
+ and_return(cache)
123
+ end
124
+
125
+ describe "#get" do
126
+ it "should do a get request passing the correct parameters" do
127
+ expect(subject.get(path, cache_params.merge(headers: headers))).to eql data
128
+ end
129
+ end
130
+
131
+ describe "#get_json" do
132
+ it "should parse the response as JSON" do
133
+ expect(subject.get_json(path, cache_params.merge(headers: headers))).to eql JSON.parse(data)
134
+ end
135
+ end
136
+ end
137
+
138
+ describe "POST method" do
139
+ before do
140
+ expect(ContentGateway::Request).
55
141
  to receive(:new).
56
142
  with(:post, "url", nil, payload, config.proxy, connection_params).
57
143
  and_return(request)
58
- expect(ContentGateway::Cache).
144
+ expect(ContentGateway::Cache).
59
145
  to receive(:new).
60
146
  with(config, "url", :post, connection_params).
61
147
  and_return(cache)
62
- end
148
+ end
63
149
 
64
- describe "#post" do
65
- it "should do a post request passing the correct parameters" do
66
- expect(subject.post(path, cache_params.merge(payload: payload))).to eql data
150
+ describe "#post" do
151
+ it "should do a post request passing the correct parameters" do
152
+ expect(subject.post(path, cache_params.merge(payload: payload))).to eql data
153
+ end
67
154
  end
68
- end
69
155
 
70
- describe "#post_json" do
71
- it "should parse the response as JSON" do
72
- expect(subject.post_json(path, cache_params.merge(payload: payload))).to eql JSON.parse(data)
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
73
160
  end
74
161
  end
75
- end
76
162
 
77
- describe "PUT method" do
78
- before do
79
- expect(ContentGateway::Request).
163
+ describe "PUT method" do
164
+ before do
165
+ expect(ContentGateway::Request).
80
166
  to receive(:new).
81
167
  with(:put, "url", nil, payload, config.proxy, connection_params).
82
168
  and_return(request)
83
- expect(ContentGateway::Cache).
169
+ expect(ContentGateway::Cache).
84
170
  to receive(:new).
85
171
  with(config, "url", :put, connection_params).
86
172
  and_return(cache)
87
- end
173
+ end
88
174
 
89
- describe "#put" do
90
- it "should do a put request passing the correct parameters" do
91
- expect(subject.put(path, cache_params.merge(payload: payload))).to eql data
175
+ describe "#put" do
176
+ it "should do a put request passing the correct parameters" do
177
+ expect(subject.put(path, cache_params.merge(payload: payload))).to eql data
178
+ end
92
179
  end
93
- end
94
180
 
95
- describe "#put_json" do
96
- it "should parse the response as JSON" do
97
- expect(subject.put_json(path, cache_params.merge(payload: payload))).to eql JSON.parse(data)
181
+ describe "#put_json" do
182
+ it "should parse the response as JSON" do
183
+ expect(subject.put_json(path, cache_params.merge(payload: payload))).to eql JSON.parse(data)
184
+ end
98
185
  end
99
186
  end
100
- end
101
187
 
102
- describe "DELETE method" do
103
- before do
104
- expect(ContentGateway::Request).
188
+ describe "DELETE method" do
189
+ before do
190
+ expect(ContentGateway::Request).
105
191
  to receive(:new).
106
192
  with(:delete, "url", nil, nil, config.proxy, connection_params).
107
193
  and_return(request)
108
- expect(ContentGateway::Cache).
194
+ expect(ContentGateway::Cache).
109
195
  to receive(:new).
110
196
  with(config, "url", :delete, connection_params).
111
197
  and_return(cache)
112
- end
198
+ end
113
199
 
114
- describe "#delete" do
115
- it "should do a delete request passing the correct parameters" do
116
- expect(subject.delete(path, cache_params.merge(payload: payload))).to eql data
200
+ describe "#delete" do
201
+ it "should do a delete request passing the correct parameters" do
202
+ expect(subject.delete(path, cache_params.merge(payload: payload))).to eql data
203
+ end
117
204
  end
118
- end
119
205
 
120
- describe "#delete_json" do
121
- it "should parse the response as JSON" do
122
- expect(subject.delete_json(path, cache_params.merge(payload: payload))).to eql JSON.parse(data)
206
+ describe "#delete_json" do
207
+ it "should parse the response as JSON" do
208
+ expect(subject.delete_json(path, cache_params.merge(payload: payload))).to eql JSON.parse(data)
209
+ end
123
210
  end
124
211
  end
125
212
  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.2.1
4
+ version: 0.3.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: 2014-11-06 00:00:00.000000000 Z
17
+ date: 2015-01-06 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: activesupport