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.
@@ -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
- server_thread = Thread.new do
14
- Rack::Handler::Thin.run MyApp::Test::Server.new, :Port => 8383
12
+ Thread.new do
13
+ Rack::Handler::Thin.run MyApp::Test::Server.new, Port: 8383
15
14
  end
16
- sleep(3) # wait a sec for the server to be booted
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 "Configuration" do
26
-
27
- it "raise when file_name not sent in" do
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 "correctly read configuration files" do
30
+ it 'correctly read configuration files' do
32
31
  RestfulClient.configure do |config|
33
- config.config_folder = "spec/config"
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 "allow accesing url configuration" do
38
+ it 'allow accesing url configuration' do
40
39
  RestfulClient.configure do |config|
41
- config.config_folder = "spec/config"
40
+ config.config_folder = 'spec/config'
42
41
  end
43
42
 
44
- expect(RestfulClient.configuration.data["posts"]["url"]).to eq("http://1.2.3.4:8383/api/v1/")
43
+ expect(RestfulClient.configuration.data['posts']['url']).to eq('http://1.2.3.4:8383/api/v1/')
45
44
  end
46
45
 
47
- it "allow accesing url configuration by environment" do
46
+ it 'allow accesing url configuration by environment' do
48
47
  RestfulClient.configure do |config|
49
- config.env_name = "production"
50
- config.config_folder = "spec/config"
48
+ config.env_name = 'production'
49
+ config.config_folder = 'spec/config'
51
50
  end
52
51
 
53
- expect(RestfulClient.configuration.data["posts"]["url"]).to eq("http://1.2.3.4:8383/api/v0/")
52
+ expect(RestfulClient.configuration.data['posts']['url']).to eq('http://1.2.3.4:8383/api/v0/')
54
53
  end
55
54
 
56
- it "allow should access with legacy configuration as well" do
55
+ it 'allow should access with legacy configuration as well' do
57
56
  RestfulClient.configure do |config|
58
- config.env_name = "production"
59
- config.config_folder = "spec/config"
60
- config.legacy_postfix = "_service"
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("pompa")["url"]).to_not eq(nil)
62
+ expect(RestfulClient.callerr_config('pompa')['url']).to_not eq(nil)
64
63
  end
65
64
 
66
- it "should register jynx with correct name in case of legacy" do
65
+ it 'should register jynx with correct name in case of legacy' do
67
66
  RestfulClient.configure do |config|
68
- config.env_name = "production"
69
- config.config_folder = "spec/config"
70
- config.legacy_postfix = "_service"
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 = "production"
81
- config.config_folder = "spec/config"
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 "correctly read the configuration from the registry" do
84
+ it 'correctly read the configuration from the registry' do
88
85
  RestfulClient.configure do |config|
89
- config.config_folder = "spec/config"
86
+ config.config_folder = 'spec/config'
90
87
  end
91
88
 
92
- expect(RestfulClient.callerr_config("posts")["url"]).to eq("http://1.2.3.4:8383/api/v0/")
89
+ expect(RestfulClient.callerr_config('posts')['url']).to eq('http://1.2.3.4:8383/api/v0/')
93
90
  end
94
91
 
95
- it "have a timeout defined for the service by default" do
92
+ it 'have a timeout defined for the service by default' do
96
93
  RestfulClient.configure do |config|
97
- config.config_folder = "spec/config"
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 "have a timeout defined for the service by default" do
100
+ it 'have a timeout defined for the service by default' do
104
101
  RestfulClient.configure do |config|
105
- config.config_folder = "spec/config"
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 "have a user agent defined for the service by default" do
109
+ it 'have a user agent defined for the service by default' do
113
110
  RestfulClient.configure do |config|
114
- config.config_folder = "spec/config"
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 "have a user agent defined for the service" do
117
+ it 'have a user agent defined for the service' do
121
118
  RestfulClient.configure do |config|
122
- config.config_folder = "spec/config"
123
- config.user_agent = "users_service"
119
+ config.config_folder = 'spec/config'
120
+ config.user_agent = 'users_service'
124
121
  end
125
122
 
126
- expect(RestfulClient.user_agent).to eq("users_service")
123
+ expect(RestfulClient.user_agent).to eq('users_service')
127
124
  end
128
125
 
129
- it "have a retries defined for the service by default" do
126
+ it 'have a retries defined for the service by default' do
130
127
  RestfulClient.configure do |config|
131
- config.config_folder = "spec/config"
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 "have a retries defined for the service by default" do
134
+ it 'have a retries defined for the service by default' do
138
135
  RestfulClient.configure do |config|
139
- config.config_folder = "spec/config"
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 "toJson" do
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 = "production"
153
- config.config_folder = "spec/config"
147
+ config.env_name = 'production'
148
+ config.config_folder = 'spec/config'
154
149
  end
155
150
 
156
- some_object = {"moshe" => "test"}
157
- res = RestfulClient.post("locally", "/bounce", some_object) { |m| m }
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 = "production"
165
- config.config_folder = "spec/config"
159
+ config.env_name = 'production'
160
+ config.config_folder = 'spec/config'
166
161
  end
167
162
 
168
- some_object = {"moshe" => "test"}.to_json
169
- res = RestfulClient.post("locally", "/bounce", some_object) { |m| m }
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 "Restful Client Calls" do
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 = "production"
181
- config.config_folder = "spec/config"
173
+ config.env_name = 'production'
174
+ config.config_folder = 'spec/config'
182
175
  config.report_method = proc do |*args|
183
- klass, message = *args
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("RestfulClientConfiguration")
182
+ expect($some_global).to eq('RestfulClientConfiguration')
190
183
  end
191
184
 
192
- it "report on a server error (end-2-end ish test)" do
185
+ it 'report on a server error (end-2-end ish test)' do
193
186
  RestfulClient.configure do |config|
194
- config.env_name = "production"
195
- config.config_folder = "spec/config"
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, message = *args
191
+ klass = args.first
199
192
  set_global(klass)
200
193
  end
201
194
  end
202
- RestfulClient.get("posts", "/a/a/a/a") { nil }
195
+ RestfulClient.get('posts', '/a/a/a/a') { nil }
203
196
 
204
- expect($some_global).to eq("RestError")
197
+ expect($some_global).to eq('RestError')
205
198
  end
206
199
 
207
- it "do not report on a client side error (http_code < 500)" do
200
+ it 'do not report on a client side error (http_code < 500)' do
208
201
  RestfulClient.configure do |config|
209
- config.env_name = "production"
210
- config.config_folder = "spec/config"
202
+ config.env_name = 'production'
203
+ config.config_folder = 'spec/config'
211
204
  config.report_method = proc do |*args|
212
- klass, message = *args
205
+ klass = args.first
213
206
  set_global(klass)
214
207
  end
215
208
  end
216
- RestfulClient.get("locally", "/client_error") { nil }
209
+ RestfulClient.get('locally', '/client_error') { nil }
217
210
 
218
211
  expect($some_global).to be_nil
219
212
  end
220
213
 
221
- it "do not report on a missing resource (http_code == 404)" do
214
+ it 'do not report on a missing resource (http_code == 404)' do
222
215
  RestfulClient.configure do |config|
223
- config.env_name = "production"
224
- config.config_folder = "spec/config"
216
+ config.env_name = 'production'
217
+ config.config_folder = 'spec/config'
225
218
  config.report_method = proc do |*args|
226
- klass, message = *args
219
+ klass = args.first
227
220
  set_global(klass)
228
221
  end
229
222
  end
230
223
 
231
- RestfulClient.get("locally", "/non_existing") { nil }
224
+ RestfulClient.get('locally', '/non_existing') { nil }
232
225
 
233
226
  expect($some_global).to be_nil
234
227
  end
235
228
 
236
- end
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
- describe "Retry call count" do
243
+ RestfulClient.get('locally', '/non_existing') { 'default' }
239
244
 
240
- it "repeat the call if retry is set " do
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 = "spec/config"
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, message = *args
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
- ##Run something that hard codedly, in the test_server, increments the counter
254
- RestfulClient.get("locally", "a/a/a/b") { |m| nil }
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("locally", "a") { "good" }
284
+ # And asset the number of retries.
285
+ res = RestfulClient.get('locally', 'a') { 'good' }
258
286
 
259
- expect(res["counter"]).to eq(4)
287
+ expect(res['counter']).to eq(4)
260
288
  end
261
-
262
289
  end
263
290
 
264
- describe "Default Value if no block is given" do
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 = "spec/config"
294
+ config.config_folder = 'spec/config'
269
295
  config.timeout = 1
270
296
  end
271
- res = RestfulClient.get("posts", "/a")
297
+ res = RestfulClient.get('posts', '/a')
272
298
  expect(res).to eq(nil)
273
299
  end
274
300
 
275
- it "should allow skiping jynx completly" do
301
+ it 'should allow skiping jynx completly' do
276
302
  RestfulClient.configure do |config|
277
- config.config_folder = "spec/config"
303
+ config.config_folder = 'spec/config'
278
304
  config.use_jynx = false
279
305
  config.timeout = 1
280
306
  end
281
- res = RestfulClient.get("posts", "/a")
307
+ res = RestfulClient.get('posts', '/a')
282
308
  expect(res).to eq(nil)
283
309
  end
284
-
285
310
  end
286
311
 
287
- describe "Uri Joining" do
288
-
289
- it "correct join two paths leading slash defined as [WithSlash : NoSlash]" do
290
- path = RestfulClientUri.uri_join("http://load-balancer-int01:9999/api/v1/", "proposals/sent/count/123")
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 "correct join two paths leading slash defined as [WithSlash : WithSlash]" do
295
- path = RestfulClientUri.uri_join("http://load-balancer-int01:9999/api/v1/", "/proposals/sent/count/123")
296
- expect(path).to eq("http://load-balancer-int01:9999/api/v1/proposals/sent/count/123")
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 "correct join two paths leading slash defined as [NoSlash : WithSlash]" do
300
- path = RestfulClientUri.uri_join("http://load-balancer-int01:9999/api/v1", "/proposals/sent/count/123")
301
- expect(path).to eq("http://load-balancer-int01:9999/api/v1/proposals/sent/count/123")
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 "correct join two paths leading slash defined as [NoSlash : NowSlash]" do
305
- path = RestfulClientUri.uri_join("http://load-balancer-int01:9999/api/v1", "proposals/sent/count/123")
306
- expect(path).to eq("http://load-balancer-int01:9999/api/v1/proposals/sent/count/123")
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 "Fake response" do
312
-
313
- it "should return fake response" do
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({ 'fake' => true })
346
+ expect(res).to eq('fake' => true)
325
347
  end
326
-
327
348
  end
328
349
 
329
- describe "custom headers" do
330
- it "should allow sending custom headers to a single post request" do
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 = "production"
333
- config.config_folder = "spec/config"
358
+ config.env_name = 'production'
359
+ config.config_folder = 'spec/config'
334
360
  end
335
361
 
336
- custom_headers = {"moshe" => "OH MY GOD ~!!"}
337
- res = RestfulClient.post("locally", "/bounce_headers/moshe", {}, {"headers" => custom_headers})
338
- expect(res).to eq(custom_headers)
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
- it "should allow sending custom headers to a single get request" do
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 = "production"
345
- config.config_folder = "spec/config"
372
+ config.env_name = 'production'
373
+ config.config_folder = 'spec/config'
346
374
  end
347
375
 
348
- custom_headers = {"moshe" => "OH MY GOD ~!!"}
349
- res = RestfulClient.get("locally", "/bounce_headers/moshe", nil, {"headers" => custom_headers})
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 "should allow sending custom headers to a single delete request" do
381
+ it 'should allow sending custom headers to a single get request' do
355
382
  RestfulClient.configure do |config|
356
- config.env_name = "production"
357
- config.config_folder = "spec/config"
383
+ config.env_name = 'production'
384
+ config.config_folder = 'spec/config'
358
385
  end
359
386
 
360
- custom_headers = {"moshe" => "OH MY GOD ~!!"}
361
- res = RestfulClient.delete("locally", "/bounce_headers/moshe", {}, {"headers" => custom_headers})
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 "should allow sending custom headers to a single put request" do
392
+ it 'should allow sending custom headers to a single delete request' do
367
393
  RestfulClient.configure do |config|
368
- config.env_name = "production"
369
- config.config_folder = "spec/config"
394
+ config.env_name = 'production'
395
+ config.config_folder = 'spec/config'
370
396
  end
371
397
 
372
- custom_headers = {"moshe" => "OH MY GOD ~!!"}
373
- res = RestfulClient.put("locally", "/bounce_headers/moshe", {}, {"headers" => custom_headers})
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 "should be possible to get url from yml for custom calls" do
416
+ it 'should be possible to get url from yml for custom calls' do
383
417
  RestfulClient.configure do |config|
384
- config.env_name = "production"
385
- config.config_folder = "spec/config"
418
+ config.env_name = 'production'
419
+ config.config_folder = 'spec/config'
386
420
  end
387
421
 
388
- expect(RestfulClient.srv_url('posts')).to eq("http://1.2.3.4:8383/api/v0/")
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
@@ -3,5 +3,5 @@ Bundler.require
3
3
 
4
4
  require 'rspec'
5
5
 
6
- Dir["./spec/support/**/*.rb"].each {|f| load(f)}
6
+ Dir['./spec/support/**/*.rb'].each { |f| load(f) }
7
7
  load("#{File.dirname(__FILE__)}/../lib/restful_client.rb")
@@ -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 == "/api/v0/a/a/a/b"
13
- @@counter = @@counter+1
14
- sleep 3
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/client_error"
21
- [ 400, {'Content-Type' => 'text/plain'}, {}.to_json ]
22
- elsif path =~ /\/api\/v0\/bounce_headers/
23
- ## this is what rack request is doing to custom headers
24
- base_name = path.split("/").last
25
- header_name = "HTTP_#{base_name.upcase}"
26
- [ 200, {'Content-Type' => 'text/plain'}, {"#{base_name}" => env[header_name]}.to_json ]
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
- [ 200, {'Content-Type' => 'text/plain'}, {counter: @@counter}.to_json ]
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