restful_client 0.1.0 → 0.3.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/.hound.yml +2 -0
- data/.ruby-style.yml +239 -0
- data/.travis.yml +5 -0
- data/Gemfile +2 -1
- data/README.md +10 -10
- data/lib/restful_client.rb +57 -46
- data/lib/restful_client_configuration.rb +12 -14
- data/lib/restful_client_logger.rb +6 -5
- data/lib/restful_client_uri.rb +0 -1
- data/restful_client.gemspec +4 -7
- data/spec/restful_client_spec.rb +191 -160
- data/spec/spec_helper.rb +1 -1
- data/spec/support/test_server.rb +19 -17
- metadata +6 -18
- data/lib/restful_client/version.rb +0 -3
data/spec/restful_client_spec.rb
CHANGED
@@ -7,13 +7,13 @@ def set_global(class_name)
|
|
7
7
|
end
|
8
8
|
|
9
9
|
describe :RestfulClient do
|
10
|
-
|
11
10
|
before(:all) do
|
12
11
|
# Start a local rack server to serve up test pages.
|
13
|
-
|
14
|
-
Rack::Handler::Thin.run MyApp::Test::Server.new, :
|
12
|
+
Thread.new do
|
13
|
+
Rack::Handler::Thin.run MyApp::Test::Server.new, Port: 8383
|
15
14
|
end
|
16
|
-
|
15
|
+
# wait a sec for the server to be booted
|
16
|
+
sleep 2
|
17
17
|
end
|
18
18
|
|
19
19
|
before(:each) do
|
@@ -22,373 +22,404 @@ describe :RestfulClient do
|
|
22
22
|
RestfulClient.configuration.reset if RestfulClient.configuration
|
23
23
|
end
|
24
24
|
|
25
|
-
describe
|
26
|
-
|
27
|
-
|
28
|
-
expect { RestfulClient.configure { } }.to raise_error
|
25
|
+
describe 'Configuration' do
|
26
|
+
it 'raise when file_name not sent in' do
|
27
|
+
expect { RestfulClient.configure {} }.to raise_error(RuntimeError)
|
29
28
|
end
|
30
29
|
|
31
|
-
it
|
30
|
+
it 'correctly read configuration files' do
|
32
31
|
RestfulClient.configure do |config|
|
33
|
-
config.config_folder =
|
32
|
+
config.config_folder = 'spec/config'
|
34
33
|
end
|
35
34
|
|
36
35
|
expect(RestfulClient.configuration.data).to_not eq(nil)
|
37
36
|
end
|
38
37
|
|
39
|
-
it
|
38
|
+
it 'allow accesing url configuration' do
|
40
39
|
RestfulClient.configure do |config|
|
41
|
-
config.config_folder =
|
40
|
+
config.config_folder = 'spec/config'
|
42
41
|
end
|
43
42
|
|
44
|
-
expect(RestfulClient.configuration.data[
|
43
|
+
expect(RestfulClient.configuration.data['posts']['url']).to eq('http://1.2.3.4:8383/api/v1/')
|
45
44
|
end
|
46
45
|
|
47
|
-
it
|
46
|
+
it 'allow accesing url configuration by environment' do
|
48
47
|
RestfulClient.configure do |config|
|
49
|
-
config.env_name =
|
50
|
-
config.config_folder =
|
48
|
+
config.env_name = 'production'
|
49
|
+
config.config_folder = 'spec/config'
|
51
50
|
end
|
52
51
|
|
53
|
-
expect(RestfulClient.configuration.data[
|
52
|
+
expect(RestfulClient.configuration.data['posts']['url']).to eq('http://1.2.3.4:8383/api/v0/')
|
54
53
|
end
|
55
54
|
|
56
|
-
it
|
55
|
+
it 'allow should access with legacy configuration as well' do
|
57
56
|
RestfulClient.configure do |config|
|
58
|
-
config.env_name =
|
59
|
-
config.config_folder =
|
60
|
-
config.legacy_postfix =
|
57
|
+
config.env_name = 'production'
|
58
|
+
config.config_folder = 'spec/config'
|
59
|
+
config.legacy_postfix = '_service'
|
61
60
|
end
|
62
61
|
|
63
|
-
expect(RestfulClient.callerr_config(
|
62
|
+
expect(RestfulClient.callerr_config('pompa')['url']).to_not eq(nil)
|
64
63
|
end
|
65
64
|
|
66
|
-
it
|
65
|
+
it 'should register jynx with correct name in case of legacy' do
|
67
66
|
RestfulClient.configure do |config|
|
68
|
-
config.env_name =
|
69
|
-
config.config_folder =
|
70
|
-
config.legacy_postfix =
|
67
|
+
config.env_name = 'production'
|
68
|
+
config.config_folder = 'spec/config'
|
69
|
+
config.legacy_postfix = '_service'
|
71
70
|
end
|
72
71
|
|
73
|
-
|
74
|
-
expect(ServiceJynx.alive?("pompa")).to eq(true)
|
72
|
+
expect(ServiceJynx.alive?('pompa')).to eq(true)
|
75
73
|
end
|
76
74
|
|
77
|
-
|
78
|
-
it "have a logger" do
|
75
|
+
it 'have a logger' do
|
79
76
|
RestfulClient.configure do |config|
|
80
|
-
config.env_name =
|
81
|
-
config.config_folder =
|
77
|
+
config.env_name = 'production'
|
78
|
+
config.config_folder = 'spec/config'
|
82
79
|
end
|
83
80
|
|
84
81
|
expect(RestfulClient.logger).to respond_to :info
|
85
82
|
end
|
86
83
|
|
87
|
-
it
|
84
|
+
it 'correctly read the configuration from the registry' do
|
88
85
|
RestfulClient.configure do |config|
|
89
|
-
config.config_folder =
|
86
|
+
config.config_folder = 'spec/config'
|
90
87
|
end
|
91
88
|
|
92
|
-
expect(RestfulClient.callerr_config(
|
89
|
+
expect(RestfulClient.callerr_config('posts')['url']).to eq('http://1.2.3.4:8383/api/v0/')
|
93
90
|
end
|
94
91
|
|
95
|
-
it
|
92
|
+
it 'have a timeout defined for the service by default' do
|
96
93
|
RestfulClient.configure do |config|
|
97
|
-
config.config_folder =
|
94
|
+
config.config_folder = 'spec/config'
|
98
95
|
end
|
99
96
|
|
100
97
|
expect(RestfulClient.timeout).to eq(10)
|
101
98
|
end
|
102
99
|
|
103
|
-
it
|
100
|
+
it 'have a timeout defined for the service by default' do
|
104
101
|
RestfulClient.configure do |config|
|
105
|
-
config.config_folder =
|
102
|
+
config.config_folder = 'spec/config'
|
106
103
|
config.timeout = 2
|
107
104
|
end
|
108
105
|
|
109
106
|
expect(RestfulClient.timeout).to eq(2)
|
110
107
|
end
|
111
108
|
|
112
|
-
it
|
109
|
+
it 'have a user agent defined for the service by default' do
|
113
110
|
RestfulClient.configure do |config|
|
114
|
-
config.config_folder =
|
111
|
+
config.config_folder = 'spec/config'
|
115
112
|
end
|
116
113
|
|
117
114
|
expect(RestfulClient.user_agent).to eq(RestfulClientConfiguration::DEFAULT_USER_AGENT)
|
118
115
|
end
|
119
116
|
|
120
|
-
it
|
117
|
+
it 'have a user agent defined for the service' do
|
121
118
|
RestfulClient.configure do |config|
|
122
|
-
config.config_folder =
|
123
|
-
config.user_agent =
|
119
|
+
config.config_folder = 'spec/config'
|
120
|
+
config.user_agent = 'users_service'
|
124
121
|
end
|
125
122
|
|
126
|
-
expect(RestfulClient.user_agent).to eq(
|
123
|
+
expect(RestfulClient.user_agent).to eq('users_service')
|
127
124
|
end
|
128
125
|
|
129
|
-
it
|
126
|
+
it 'have a retries defined for the service by default' do
|
130
127
|
RestfulClient.configure do |config|
|
131
|
-
config.config_folder =
|
128
|
+
config.config_folder = 'spec/config'
|
132
129
|
end
|
133
130
|
|
134
131
|
expect(RestfulClient.retries).to eq(2)
|
135
132
|
end
|
136
133
|
|
137
|
-
it
|
134
|
+
it 'have a retries defined for the service by default' do
|
138
135
|
RestfulClient.configure do |config|
|
139
|
-
config.config_folder =
|
136
|
+
config.config_folder = 'spec/config'
|
140
137
|
config.retries = 15
|
141
138
|
end
|
142
139
|
|
143
140
|
expect(RestfulClient.retries).to eq(15)
|
144
141
|
end
|
145
|
-
|
146
142
|
end
|
147
143
|
|
148
|
-
describe
|
149
|
-
|
150
|
-
it "automatically run to_json on an object" do
|
144
|
+
describe 'toJson' do
|
145
|
+
it 'automatically run to_json on an object' do
|
151
146
|
RestfulClient.configure do |config|
|
152
|
-
config.env_name =
|
153
|
-
config.config_folder =
|
147
|
+
config.env_name = 'production'
|
148
|
+
config.config_folder = 'spec/config'
|
154
149
|
end
|
155
150
|
|
156
|
-
some_object = {
|
157
|
-
res = RestfulClient.post(
|
151
|
+
some_object = { 'moshe' => 'test' }
|
152
|
+
res = RestfulClient.post('locally', '/bounce', some_object) { |m| m }
|
158
153
|
|
159
154
|
expect(res).to eq(some_object)
|
160
155
|
end
|
161
156
|
|
162
157
|
it "doesn't re-run json on data that was already a json object" do
|
163
158
|
RestfulClient.configure do |config|
|
164
|
-
config.env_name =
|
165
|
-
config.config_folder =
|
159
|
+
config.env_name = 'production'
|
160
|
+
config.config_folder = 'spec/config'
|
166
161
|
end
|
167
162
|
|
168
|
-
some_object = {
|
169
|
-
res = RestfulClient.post(
|
163
|
+
some_object = { 'moshe' => 'test' }.to_json
|
164
|
+
res = RestfulClient.post('locally', '/bounce', some_object) { |m| m }
|
170
165
|
|
171
166
|
expect(res).to eq(JSON.parse(some_object))
|
172
167
|
end
|
173
|
-
|
174
168
|
end
|
175
169
|
|
176
|
-
describe
|
177
|
-
|
178
|
-
it "allow sending in a reporting method (such as graylog/ airbrake instrumentiation)" do
|
170
|
+
describe 'Restful Client Calls' do
|
171
|
+
it 'allow sending in a reporting method (such as graylog/ airbrake instrumentiation)' do
|
179
172
|
RestfulClient.configure do |config|
|
180
|
-
config.env_name =
|
181
|
-
config.config_folder =
|
173
|
+
config.env_name = 'production'
|
174
|
+
config.config_folder = 'spec/config'
|
182
175
|
config.report_method = proc do |*args|
|
183
|
-
klass
|
176
|
+
klass = args.first
|
184
177
|
set_global(klass)
|
185
178
|
end
|
186
179
|
end
|
187
180
|
RestfulClient.configuration.report_on
|
188
181
|
|
189
|
-
expect($some_global).to eq(
|
182
|
+
expect($some_global).to eq('RestfulClientConfiguration')
|
190
183
|
end
|
191
184
|
|
192
|
-
it
|
185
|
+
it 'report on a server error (end-2-end ish test)' do
|
193
186
|
RestfulClient.configure do |config|
|
194
|
-
config.env_name =
|
195
|
-
config.config_folder =
|
187
|
+
config.env_name = 'production'
|
188
|
+
config.config_folder = 'spec/config'
|
196
189
|
config.timeout = 1
|
197
190
|
config.report_method = proc do |*args|
|
198
|
-
klass
|
191
|
+
klass = args.first
|
199
192
|
set_global(klass)
|
200
193
|
end
|
201
194
|
end
|
202
|
-
RestfulClient.get(
|
195
|
+
RestfulClient.get('posts', '/a/a/a/a') { nil }
|
203
196
|
|
204
|
-
expect($some_global).to eq(
|
197
|
+
expect($some_global).to eq('RestError')
|
205
198
|
end
|
206
199
|
|
207
|
-
it
|
200
|
+
it 'do not report on a client side error (http_code < 500)' do
|
208
201
|
RestfulClient.configure do |config|
|
209
|
-
config.env_name =
|
210
|
-
config.config_folder =
|
202
|
+
config.env_name = 'production'
|
203
|
+
config.config_folder = 'spec/config'
|
211
204
|
config.report_method = proc do |*args|
|
212
|
-
klass
|
205
|
+
klass = args.first
|
213
206
|
set_global(klass)
|
214
207
|
end
|
215
208
|
end
|
216
|
-
RestfulClient.get(
|
209
|
+
RestfulClient.get('locally', '/client_error') { nil }
|
217
210
|
|
218
211
|
expect($some_global).to be_nil
|
219
212
|
end
|
220
213
|
|
221
|
-
it
|
214
|
+
it 'do not report on a missing resource (http_code == 404)' do
|
222
215
|
RestfulClient.configure do |config|
|
223
|
-
config.env_name =
|
224
|
-
config.config_folder =
|
216
|
+
config.env_name = 'production'
|
217
|
+
config.config_folder = 'spec/config'
|
225
218
|
config.report_method = proc do |*args|
|
226
|
-
klass
|
219
|
+
klass = args.first
|
227
220
|
set_global(klass)
|
228
221
|
end
|
229
222
|
end
|
230
223
|
|
231
|
-
RestfulClient.get(
|
224
|
+
RestfulClient.get('locally', '/non_existing') { nil }
|
232
225
|
|
233
226
|
expect($some_global).to be_nil
|
234
227
|
end
|
235
228
|
|
236
|
-
|
229
|
+
describe :JynxSetDownScenarios do
|
230
|
+
it 'do not fail jynx on a missing (http_code == 404), when failures are over max (10)' do
|
231
|
+
RestfulClient.configure do |config|
|
232
|
+
config.env_name = 'production'
|
233
|
+
config.config_folder = 'spec/config'
|
234
|
+
config.report_method = proc do |*args|
|
235
|
+
klass = args.first
|
236
|
+
set_global(klass)
|
237
|
+
end
|
238
|
+
end
|
239
|
+
0.upto(9) do
|
240
|
+
RestfulClient.get('locally', '/non_existing') { 'default' }
|
241
|
+
end
|
237
242
|
|
238
|
-
|
243
|
+
RestfulClient.get('locally', '/non_existing') { 'default' }
|
239
244
|
|
240
|
-
|
245
|
+
expect($some_global).to_not eq('ServiceJynx')
|
246
|
+
end
|
247
|
+
|
248
|
+
it 'should fail jynx on a bad return code (http_code => 500), when failures are over max (10)' do
|
249
|
+
RestfulClient.configure do |config|
|
250
|
+
config.env_name = 'production'
|
251
|
+
config.config_folder = 'spec/config'
|
252
|
+
config.report_method = proc do |*args|
|
253
|
+
klass = args.first
|
254
|
+
set_global(klass)
|
255
|
+
end
|
256
|
+
end
|
257
|
+
0.upto(9) do
|
258
|
+
RestfulClient.get('locally', '/server_error') { 'default' }
|
259
|
+
end
|
260
|
+
|
261
|
+
RestfulClient.get('locally', '/server_error') { 'default' }
|
241
262
|
|
263
|
+
expect($some_global).to eq('ServiceJynx')
|
264
|
+
end
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
describe 'Retry call count' do
|
269
|
+
it 'repeat the call if retry is set ' do
|
242
270
|
RestfulClient.configure do |config|
|
243
|
-
config.config_folder =
|
271
|
+
config.config_folder = 'spec/config'
|
244
272
|
config.retries = 3
|
245
273
|
config.timeout = 2
|
246
274
|
config.report_method = proc do |*args|
|
247
|
-
klass
|
275
|
+
klass = args.first
|
248
276
|
set_global(klass)
|
249
277
|
end
|
250
278
|
end
|
251
279
|
|
252
280
|
# flow is a little wierdish
|
253
|
-
|
254
|
-
RestfulClient.get(
|
281
|
+
# #Run something that hard codedly, in the test_server, increments the counter
|
282
|
+
RestfulClient.get('locally', 'a/a/a/b') { |_m| nil }
|
255
283
|
# Now checksomething that returns "200", put also the global server counter
|
256
|
-
# And asset the number of retries.
|
257
|
-
res = RestfulClient.get(
|
284
|
+
# And asset the number of retries.
|
285
|
+
res = RestfulClient.get('locally', 'a') { 'good' }
|
258
286
|
|
259
|
-
expect(res[
|
287
|
+
expect(res['counter']).to eq(4)
|
260
288
|
end
|
261
|
-
|
262
289
|
end
|
263
290
|
|
264
|
-
describe
|
265
|
-
|
266
|
-
it "should return nil when no value is given" do
|
291
|
+
describe 'Default Value if no block is given' do
|
292
|
+
it 'should return nil when no value is given' do
|
267
293
|
RestfulClient.configure do |config|
|
268
|
-
config.config_folder =
|
294
|
+
config.config_folder = 'spec/config'
|
269
295
|
config.timeout = 1
|
270
296
|
end
|
271
|
-
res = RestfulClient.get(
|
297
|
+
res = RestfulClient.get('posts', '/a')
|
272
298
|
expect(res).to eq(nil)
|
273
299
|
end
|
274
300
|
|
275
|
-
it
|
301
|
+
it 'should allow skiping jynx completly' do
|
276
302
|
RestfulClient.configure do |config|
|
277
|
-
config.config_folder =
|
303
|
+
config.config_folder = 'spec/config'
|
278
304
|
config.use_jynx = false
|
279
305
|
config.timeout = 1
|
280
306
|
end
|
281
|
-
res = RestfulClient.get(
|
307
|
+
res = RestfulClient.get('posts', '/a')
|
282
308
|
expect(res).to eq(nil)
|
283
309
|
end
|
284
|
-
|
285
310
|
end
|
286
311
|
|
287
|
-
describe
|
288
|
-
|
289
|
-
|
290
|
-
path
|
291
|
-
expect(path).to eq("http://load-balancer-int01:9999/api/v1/proposals/sent/count/123")
|
312
|
+
describe 'Uri Joining' do
|
313
|
+
it 'correct join two paths leading slash defined as [WithSlash : NoSlash]' do
|
314
|
+
path = RestfulClientUri.uri_join('http://load-balancer-int01:9999/api/v1/', 'proposals/sent/count/123')
|
315
|
+
expect(path).to eq('http://load-balancer-int01:9999/api/v1/proposals/sent/count/123')
|
292
316
|
end
|
293
317
|
|
294
|
-
it
|
295
|
-
path = RestfulClientUri.uri_join(
|
296
|
-
expect(path).to eq(
|
318
|
+
it 'correct join two paths leading slash defined as [WithSlash : WithSlash]' do
|
319
|
+
path = RestfulClientUri.uri_join('http://load-balancer-int01:9999/api/v1/', '/proposals/sent/count/123')
|
320
|
+
expect(path).to eq('http://load-balancer-int01:9999/api/v1/proposals/sent/count/123')
|
297
321
|
end
|
298
322
|
|
299
|
-
it
|
300
|
-
path = RestfulClientUri.uri_join(
|
301
|
-
expect(path).to eq(
|
323
|
+
it 'correct join two paths leading slash defined as [NoSlash : WithSlash]' do
|
324
|
+
path = RestfulClientUri.uri_join('http://load-balancer-int01:9999/api/v1', '/proposals/sent/count/123')
|
325
|
+
expect(path).to eq('http://load-balancer-int01:9999/api/v1/proposals/sent/count/123')
|
302
326
|
end
|
303
327
|
|
304
|
-
it
|
305
|
-
path = RestfulClientUri.uri_join(
|
306
|
-
expect(path).to eq(
|
328
|
+
it 'correct join two paths leading slash defined as [NoSlash : NowSlash]' do
|
329
|
+
path = RestfulClientUri.uri_join('http://load-balancer-int01:9999/api/v1', 'proposals/sent/count/123')
|
330
|
+
expect(path).to eq('http://load-balancer-int01:9999/api/v1/proposals/sent/count/123')
|
307
331
|
end
|
308
|
-
|
309
332
|
end
|
310
333
|
|
311
|
-
describe
|
312
|
-
|
313
|
-
|
314
|
-
RestfulClient.configure { |config| config.config_folder = "spec/config" }
|
334
|
+
describe 'Fake response' do
|
335
|
+
it 'should return fake response' do
|
336
|
+
RestfulClient.configure { |config| config.config_folder = 'spec/config' }
|
315
337
|
|
316
338
|
RestfulClient.fake('locally', 'fake/me') do
|
317
339
|
Typhoeus::Response.new(
|
318
340
|
code: 200,
|
319
|
-
headers: {'Content-Type' => 'application/json'},
|
341
|
+
headers: { 'Content-Type' => 'application/json' },
|
320
342
|
body: { 'fake' => true }.to_json)
|
321
343
|
end
|
322
344
|
|
323
345
|
res = RestfulClient.get('locally', 'fake/me') { nil }
|
324
|
-
expect(res).to eq(
|
346
|
+
expect(res).to eq('fake' => true)
|
325
347
|
end
|
326
|
-
|
327
348
|
end
|
328
349
|
|
329
|
-
describe
|
330
|
-
it
|
350
|
+
describe 'extra args' do
|
351
|
+
it 'should allow sending extra arguments as art of the typehouse request if assigned' do
|
352
|
+
expect(Typhoeus::Request).to receive(:new).with(anything,
|
353
|
+
headers: { 'Accept' => 'application/json' },
|
354
|
+
method: 'GET', timeout: 10, params: nil,
|
355
|
+
userpwd: 'user:password')
|
356
|
+
|
331
357
|
RestfulClient.configure do |config|
|
332
|
-
config.env_name =
|
333
|
-
config.config_folder =
|
358
|
+
config.env_name = 'production'
|
359
|
+
config.config_folder = 'spec/config'
|
334
360
|
end
|
335
361
|
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
362
|
+
extra_args = { 'args' => { userpwd: 'user:password' } }
|
363
|
+
RestfulClient.get('posts', '/comments/123', nil, extra_args) do
|
364
|
+
[] # default value to be returned on failure
|
365
|
+
end
|
340
366
|
end
|
367
|
+
end
|
341
368
|
|
342
|
-
|
369
|
+
describe 'custom headers' do
|
370
|
+
it 'should allow sending custom headers to a single post request' do
|
343
371
|
RestfulClient.configure do |config|
|
344
|
-
config.env_name =
|
345
|
-
config.config_folder =
|
372
|
+
config.env_name = 'production'
|
373
|
+
config.config_folder = 'spec/config'
|
346
374
|
end
|
347
375
|
|
348
|
-
custom_headers = {
|
349
|
-
res = RestfulClient.
|
376
|
+
custom_headers = { 'moshe' => 'OH MY GOD ~!!' }
|
377
|
+
res = RestfulClient.post('locally', '/bounce_headers/moshe', {}, 'headers' => custom_headers)
|
350
378
|
expect(res).to eq(custom_headers)
|
351
|
-
|
352
379
|
end
|
353
380
|
|
354
|
-
it
|
381
|
+
it 'should allow sending custom headers to a single get request' do
|
355
382
|
RestfulClient.configure do |config|
|
356
|
-
config.env_name =
|
357
|
-
config.config_folder =
|
383
|
+
config.env_name = 'production'
|
384
|
+
config.config_folder = 'spec/config'
|
358
385
|
end
|
359
386
|
|
360
|
-
custom_headers = {
|
361
|
-
res = RestfulClient.
|
387
|
+
custom_headers = { 'moshe' => 'OH MY GOD ~!!' }
|
388
|
+
res = RestfulClient.get('locally', '/bounce_headers/moshe', nil, 'headers' => custom_headers)
|
362
389
|
expect(res).to eq(custom_headers)
|
363
|
-
|
364
390
|
end
|
365
391
|
|
366
|
-
it
|
392
|
+
it 'should allow sending custom headers to a single delete request' do
|
367
393
|
RestfulClient.configure do |config|
|
368
|
-
config.env_name =
|
369
|
-
config.config_folder =
|
394
|
+
config.env_name = 'production'
|
395
|
+
config.config_folder = 'spec/config'
|
370
396
|
end
|
371
397
|
|
372
|
-
custom_headers = {
|
373
|
-
res = RestfulClient.
|
398
|
+
custom_headers = { 'moshe' => 'OH MY GOD ~!!' }
|
399
|
+
res = RestfulClient.delete('locally', '/bounce_headers/moshe', {}, 'headers' => custom_headers)
|
374
400
|
expect(res).to eq(custom_headers)
|
375
|
-
|
376
401
|
end
|
377
402
|
|
403
|
+
it 'should allow sending custom headers to a single put request' do
|
404
|
+
RestfulClient.configure do |config|
|
405
|
+
config.env_name = 'production'
|
406
|
+
config.config_folder = 'spec/config'
|
407
|
+
end
|
378
408
|
|
409
|
+
custom_headers = { 'moshe' => 'OH MY GOD ~!!' }
|
410
|
+
res = RestfulClient.put('locally', '/bounce_headers/moshe', {}, 'headers' => custom_headers)
|
411
|
+
expect(res).to eq(custom_headers)
|
412
|
+
end
|
379
413
|
end
|
380
414
|
|
381
415
|
describe :PlainURL do
|
382
|
-
it
|
416
|
+
it 'should be possible to get url from yml for custom calls' do
|
383
417
|
RestfulClient.configure do |config|
|
384
|
-
config.env_name =
|
385
|
-
config.config_folder =
|
418
|
+
config.env_name = 'production'
|
419
|
+
config.config_folder = 'spec/config'
|
386
420
|
end
|
387
421
|
|
388
|
-
expect(RestfulClient.srv_url('posts')).to eq(
|
422
|
+
expect(RestfulClient.srv_url('posts')).to eq('http://1.2.3.4:8383/api/v0/')
|
389
423
|
end
|
390
424
|
end
|
391
|
-
|
392
|
-
|
393
425
|
end
|
394
|
-
|
data/spec/spec_helper.rb
CHANGED
data/spec/support/test_server.rb
CHANGED
@@ -9,25 +9,27 @@ module MyApp
|
|
9
9
|
def call(env)
|
10
10
|
path = Rack::Utils.unescape(env['PATH_INFO'])
|
11
11
|
### Hacky just to allow sending a global counter
|
12
|
-
if path ==
|
13
|
-
@@counter
|
14
|
-
sleep
|
15
|
-
[
|
16
|
-
elsif path ==
|
17
|
-
[
|
18
|
-
elsif path ==
|
19
|
-
[
|
20
|
-
elsif path ==
|
21
|
-
[
|
22
|
-
elsif path
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
12
|
+
if path == '/api/v0/a/a/a/b'
|
13
|
+
@@counter += 1
|
14
|
+
sleep 2
|
15
|
+
[500, { 'Content-Type' => 'application/json' }, { counter: @@counter }.to_json]
|
16
|
+
elsif path == '/api/v0/bounce'
|
17
|
+
[200, { 'Content-Type' => 'text/plain' }, env['rack.input'].gets]
|
18
|
+
elsif path == '/api/v0/non_existing'
|
19
|
+
[404, { 'Content-Type' => 'text/plain' }, {}.to_json]
|
20
|
+
elsif path == '/api/v0/server_error'
|
21
|
+
[503, { 'Content-Type' => 'text/plain' }, {}.to_json]
|
22
|
+
elsif path == '/api/v0/client_error'
|
23
|
+
[400, { 'Content-Type' => 'text/plain' }, {}.to_json]
|
24
|
+
elsif path =~ %r{\/api\/v0\/bounce_headers}
|
25
|
+
## this is what rack request is doing to custom headers
|
26
|
+
base_name = path.split('/').last
|
27
|
+
header_name = "HTTP_#{base_name.upcase}"
|
28
|
+
[200, { 'Content-Type' => 'text/plain' }, { "#{base_name}" => env[header_name] }.to_json]
|
27
29
|
else
|
28
|
-
[
|
30
|
+
[200, { 'Content-Type' => 'text/plain' }, { counter: @@counter }.to_json]
|
29
31
|
end
|
30
32
|
end
|
31
33
|
end
|
32
34
|
end
|
33
|
-
end
|
35
|
+
end
|