artirix_data_models 1.0.0.beta6 → 1.0.0.beta8
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa6ee7f791b64b681b98229190120f8ba464a0f1
|
4
|
+
data.tar.gz: 88831d196f2b2c278cedfae4f5e3dd3ca71230e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9ff61cc1ed744df94441200b85fd1ecc6213ab5f25c0d94bbdc0de7d151a2bc33f6a3241448e801c501d993d9333abe9ab28db7b411589f900a122f0d90ba48
|
7
|
+
data.tar.gz: 61d8998bdc314ce0e3bdbe94f80826858b4b8d80500f3af51fb8ef5bebe6375e99510e76ba5b16a9e5f2d1c3abb59a3e61c05247dc9502b1f43f56e1c74ba112
|
data/README.md
CHANGED
@@ -320,6 +320,21 @@ end
|
|
320
320
|
|
321
321
|
## Changes
|
322
322
|
|
323
|
+
### 1.0.0.beta8(YANKED)
|
324
|
+
|
325
|
+
- allow non json responses in gateway `#perform`, by passing `json_parse_response: false`.
|
326
|
+
|
327
|
+
Example:
|
328
|
+
|
329
|
+
```ruby
|
330
|
+
gateway.post path_to_be_bad_json, json_parse_response: false
|
331
|
+
# => gives the response.body to the response_adaptor with no json parsing
|
332
|
+
```
|
333
|
+
|
334
|
+
- adds support in DAOs to pass that option to the Gateway.
|
335
|
+
|
336
|
+
### ~1.0.0.beta7~ (YANKED)
|
337
|
+
|
323
338
|
### 1.0.0.beta6
|
324
339
|
|
325
340
|
- prevent crash if the parsed_data is nil when building a new model from the single response.
|
@@ -175,6 +175,7 @@ class ArtirixDataModels::BasicModelDAO
|
|
175
175
|
def perform_get(path,
|
176
176
|
fake: nil,
|
177
177
|
response_adaptor: nil,
|
178
|
+
json_parse_response: true,
|
178
179
|
body: nil,
|
179
180
|
fake_response: nil,
|
180
181
|
cache_adaptor: nil,
|
@@ -188,6 +189,7 @@ class ArtirixDataModels::BasicModelDAO
|
|
188
189
|
|
189
190
|
g.get path,
|
190
191
|
response_adaptor: response_adaptor,
|
192
|
+
json_parse_response: json_parse_response,
|
191
193
|
body: body,
|
192
194
|
timeout: timeout,
|
193
195
|
fake: fake,
|
@@ -200,6 +202,7 @@ class ArtirixDataModels::BasicModelDAO
|
|
200
202
|
def perform_post(path,
|
201
203
|
fake: nil,
|
202
204
|
response_adaptor: nil,
|
205
|
+
json_parse_response: true,
|
203
206
|
body: nil,
|
204
207
|
fake_response: nil,
|
205
208
|
cache_adaptor: nil,
|
@@ -213,6 +216,7 @@ class ArtirixDataModels::BasicModelDAO
|
|
213
216
|
|
214
217
|
g.post path,
|
215
218
|
response_adaptor: response_adaptor,
|
219
|
+
json_parse_response: json_parse_response,
|
216
220
|
body: body,
|
217
221
|
timeout: timeout,
|
218
222
|
fake: fake,
|
@@ -224,6 +228,7 @@ class ArtirixDataModels::BasicModelDAO
|
|
224
228
|
def perform_put(path,
|
225
229
|
fake: nil,
|
226
230
|
response_adaptor: nil,
|
231
|
+
json_parse_response: true,
|
227
232
|
body: nil,
|
228
233
|
fake_response: nil,
|
229
234
|
cache_adaptor: nil,
|
@@ -237,6 +242,7 @@ class ArtirixDataModels::BasicModelDAO
|
|
237
242
|
|
238
243
|
g.put path,
|
239
244
|
response_adaptor: response_adaptor,
|
245
|
+
json_parse_response: json_parse_response,
|
240
246
|
body: body,
|
241
247
|
timeout: timeout,
|
242
248
|
fake: fake,
|
@@ -248,6 +254,7 @@ class ArtirixDataModels::BasicModelDAO
|
|
248
254
|
def perform_patch(path,
|
249
255
|
fake: nil,
|
250
256
|
response_adaptor: nil,
|
257
|
+
json_parse_response: true,
|
251
258
|
body: nil,
|
252
259
|
fake_response: nil,
|
253
260
|
cache_adaptor: nil,
|
@@ -261,6 +268,7 @@ class ArtirixDataModels::BasicModelDAO
|
|
261
268
|
|
262
269
|
g.patch path,
|
263
270
|
response_adaptor: response_adaptor,
|
271
|
+
json_parse_response: json_parse_response,
|
264
272
|
body: body,
|
265
273
|
timeout: timeout,
|
266
274
|
fake: fake,
|
@@ -272,6 +280,7 @@ class ArtirixDataModels::BasicModelDAO
|
|
272
280
|
def perform_delete(path,
|
273
281
|
fake: nil,
|
274
282
|
response_adaptor: nil,
|
283
|
+
json_parse_response: true,
|
275
284
|
body: nil,
|
276
285
|
fake_response: nil,
|
277
286
|
cache_adaptor: nil,
|
@@ -285,6 +294,7 @@ class ArtirixDataModels::BasicModelDAO
|
|
285
294
|
|
286
295
|
g.delete path,
|
287
296
|
response_adaptor: response_adaptor,
|
297
|
+
json_parse_response: json_parse_response,
|
288
298
|
body: body,
|
289
299
|
timeout: timeout,
|
290
300
|
fake: fake,
|
@@ -51,6 +51,7 @@ class ArtirixDataModels::DataGateway
|
|
51
51
|
authorization_bearer: nil,
|
52
52
|
authorization_token_hash: nil,
|
53
53
|
headers: nil,
|
54
|
+
json_parse_response: true,
|
54
55
|
**_ignored_options)
|
55
56
|
|
56
57
|
if fake
|
@@ -80,6 +81,7 @@ class ArtirixDataModels::DataGateway
|
|
80
81
|
end
|
81
82
|
|
82
83
|
parse_response result: result,
|
84
|
+
json_parse_response: json_parse_response,
|
83
85
|
response_adaptor: response_adaptor,
|
84
86
|
method: method,
|
85
87
|
path: path
|
@@ -193,11 +195,13 @@ class ArtirixDataModels::DataGateway
|
|
193
195
|
end
|
194
196
|
end
|
195
197
|
|
196
|
-
def parse_response(result:, response_adaptor:, path:, method:)
|
197
|
-
if result.
|
198
|
+
def parse_response(result:, response_adaptor:, path:, method:, json_parse_response: true)
|
199
|
+
if result.blank?
|
200
|
+
parsed_response = nil
|
201
|
+
elsif json_parse_response
|
198
202
|
parsed_response = Oj.load result, symbol_keys: true
|
199
203
|
else
|
200
|
-
parsed_response =
|
204
|
+
parsed_response = result
|
201
205
|
end
|
202
206
|
|
203
207
|
if response_adaptor.present?
|
@@ -11,6 +11,8 @@ RSpec.describe ArtirixDataModels::DataGateway, type: :model do
|
|
11
11
|
Given(:token_hash2) { { x: 'some', y: 'whaat' } }
|
12
12
|
Given(:token_str2) { Faraday::Request::Authorization.build_hash('Token', token_hash2) }
|
13
13
|
|
14
|
+
Given(:non_json_response) { 'oh yeah' }
|
15
|
+
|
14
16
|
describe '.new' do
|
15
17
|
context 'without connection' do
|
16
18
|
Given(:connection_url) { 'http://example.com/other' }
|
@@ -348,31 +350,31 @@ RSpec.describe ArtirixDataModels::DataGateway, type: :model do
|
|
348
350
|
|
349
351
|
connection_stubs.get(path_to_be_not_found) { |env| [404, {}, ''] }
|
350
352
|
connection_stubs.get(path_to_fail) { |env| [500, {}, ''] }
|
351
|
-
connection_stubs.get(path_to_be_bad_json) { |env| [200, {},
|
353
|
+
connection_stubs.get(path_to_be_bad_json) { |env| [200, {}, non_json_response] }
|
352
354
|
connection_stubs.get(path_to_be_empty) { |env| [200, {}, ''] }
|
353
355
|
|
354
356
|
# stub posts
|
355
357
|
connection_stubs.post(path_to_be_not_found) { |env| [404, {}, ''] }
|
356
358
|
connection_stubs.post(path_to_fail) { |env| [500, {}, ''] }
|
357
|
-
connection_stubs.post(path_to_be_bad_json) { |env| [200, {},
|
359
|
+
connection_stubs.post(path_to_be_bad_json) { |env| [200, {}, non_json_response] }
|
358
360
|
connection_stubs.post(path_to_be_empty) { |env| [200, {}, ''] }
|
359
361
|
|
360
362
|
# stub put
|
361
363
|
connection_stubs.put(path_to_be_not_found) { |env| [404, {}, ''] }
|
362
364
|
connection_stubs.put(path_to_fail) { |env| [500, {}, ''] }
|
363
|
-
connection_stubs.put(path_to_be_bad_json) { |env| [200, {},
|
365
|
+
connection_stubs.put(path_to_be_bad_json) { |env| [200, {}, non_json_response] }
|
364
366
|
connection_stubs.put(path_to_be_empty) { |env| [200, {}, ''] }
|
365
367
|
|
366
368
|
# stub patch
|
367
369
|
connection_stubs.patch(path_to_be_not_found) { |env| [404, {}, ''] }
|
368
370
|
connection_stubs.patch(path_to_fail) { |env| [500, {}, ''] }
|
369
|
-
connection_stubs.patch(path_to_be_bad_json) { |env| [200, {},
|
371
|
+
connection_stubs.patch(path_to_be_bad_json) { |env| [200, {}, non_json_response] }
|
370
372
|
connection_stubs.patch(path_to_be_empty) { |env| [200, {}, ''] }
|
371
373
|
|
372
374
|
# stub delete
|
373
375
|
connection_stubs.delete(path_to_be_not_found) { |env| [404, {}, ''] }
|
374
376
|
connection_stubs.delete(path_to_fail) { |env| [500, {}, ''] }
|
375
|
-
connection_stubs.delete(path_to_be_bad_json) { |env| [200, {},
|
377
|
+
connection_stubs.delete(path_to_be_bad_json) { |env| [200, {}, non_json_response] }
|
376
378
|
connection_stubs.delete(path_to_be_empty) { |env| [200, {}, ''] }
|
377
379
|
end
|
378
380
|
|
@@ -454,8 +456,15 @@ RSpec.describe ArtirixDataModels::DataGateway, type: :model do
|
|
454
456
|
end
|
455
457
|
|
456
458
|
context 'when receiving bad json' do
|
457
|
-
|
458
|
-
|
459
|
+
context 'normal behaviour' do
|
460
|
+
When(:result) { gateway.post path_to_be_bad_json }
|
461
|
+
Then { result == Failure(ArtirixDataModels::DataGateway::ParseError) }
|
462
|
+
end
|
463
|
+
|
464
|
+
context 'if defining `json_parse_response: false`' do
|
465
|
+
When(:result) { gateway.post path_to_be_bad_json, json_parse_response: false }
|
466
|
+
Then { result == non_json_response}
|
467
|
+
end
|
459
468
|
end
|
460
469
|
|
461
470
|
context 'when receiving empty response' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: artirix_data_models
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.beta8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eduardo Turiño
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|