ocean-rails 3.8.9 → 3.9.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/lib/ocean/api_remote_resource.rb +45 -42
- data/lib/ocean/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c03d917f00041083de25676b0e29d98840a38e88
|
4
|
+
data.tar.gz: 364ddfa8ad3ef5f0bf3c371cc92569b1bd982dab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98554e6882e089e75b0751bdd879c7e3d9c4dde7ff90a1f2d778c17b552fc3ae71d99e4b5003bf8d02df144052bfa8ac016ed892037e63ac4348a9e2a03a65b4
|
7
|
+
data.tar.gz: edbe8eee4187fc1fe0a284f69e6bffb33ec825c1d203f275d66c41a65fd04a886c6d19ac788643088e9ec88c9be324b3e42375ff63519fe713a7fca01b94139f
|
@@ -130,7 +130,7 @@ class Api
|
|
130
130
|
#
|
131
131
|
class RemoteResource
|
132
132
|
|
133
|
-
attr_reader :uri, :content_type, :retries, :backoff_time, :backoff_rate, :backoff_max
|
133
|
+
attr_reader :uri, :args, :content_type, :retries, :backoff_time, :backoff_rate, :backoff_max
|
134
134
|
attr_reader :raw, :resource, :resource_type, :status, :headers, :credentials, :x_api_token
|
135
135
|
attr_reader :status_message, :response, :etag
|
136
136
|
|
@@ -140,11 +140,12 @@ class Api
|
|
140
140
|
# the default values, they will be used instead. Specifying only one of them is not
|
141
141
|
# permitted.
|
142
142
|
#
|
143
|
-
def initialize(uri, type="application/json",
|
143
|
+
def initialize(uri, type="application/json", args: nil,
|
144
144
|
credentials: nil, x_api_token: nil,
|
145
145
|
retries: 3, backoff_time: 1, backoff_rate: 0.9, backoff_max: 30)
|
146
146
|
super()
|
147
147
|
@uri = uri
|
148
|
+
@args = args
|
148
149
|
@content_type = type
|
149
150
|
@retries = retries
|
150
151
|
@backoff_time = backoff_time
|
@@ -253,7 +254,7 @@ class Api
|
|
253
254
|
# otherwise returns the resource itself. The args are passed directly to +new+.
|
254
255
|
#
|
255
256
|
def self.get!(*args)
|
256
|
-
|
257
|
+
new(*args).send :_retrieve
|
257
258
|
end
|
258
259
|
|
259
260
|
#
|
@@ -272,14 +273,15 @@ class Api
|
|
272
273
|
# if they occur, otherwise will return the resource itself.
|
273
274
|
#
|
274
275
|
def get!(hlink=nil, args: nil)
|
275
|
-
|
276
|
+
_retrieve unless present?
|
276
277
|
hlink = hlink.to_s if hlink
|
277
|
-
if !hlink || hlink == 'self'
|
278
|
+
if !args && (!hlink || hlink == 'self')
|
278
279
|
self
|
279
280
|
else
|
280
281
|
hl_data = hyperlink[hlink]
|
281
282
|
raise HyperlinkMissing, "#{resource_type} has no #{hlink} hyperlink" unless hl_data
|
282
|
-
RemoteResource.get!(hl_data['href']
|
283
|
+
RemoteResource.get!(hl_data['href'], args: args, retries: retries, backoff_time: backoff_time,
|
284
|
+
backoff_rate: backoff_rate, backoff_max: backoff_max)
|
283
285
|
end
|
284
286
|
end
|
285
287
|
|
@@ -288,15 +290,16 @@ class Api
|
|
288
290
|
# exceptions if problems occur, but will always return the resource itself.
|
289
291
|
# A missing hyperlink, though, will always raise a HyperlinkMissing exception.
|
290
292
|
#
|
291
|
-
def get(hlink=nil)
|
293
|
+
def get(hlink=nil, args: nil)
|
292
294
|
get! rescue nil
|
293
295
|
hlink = hlink.to_s if hlink
|
294
|
-
if !hlink || hlink == 'self'
|
296
|
+
if !args && (!hlink || hlink == 'self')
|
295
297
|
self
|
296
298
|
else
|
297
299
|
hl_data = hyperlink[hlink]
|
298
300
|
raise HyperlinkMissing, "#{resource_type} has no #{hlink} hyperlink" unless hl_data
|
299
|
-
RemoteResource.get(hl_data['href']
|
301
|
+
RemoteResource.get(hl_data['href'], args: args, retries: retries, backoff_time: backoff_time,
|
302
|
+
backoff_rate: backoff_rate, backoff_max: backoff_max)
|
300
303
|
end
|
301
304
|
end
|
302
305
|
|
@@ -308,13 +311,14 @@ class Api
|
|
308
311
|
def put!(hlink=nil, args: nil, body: {})
|
309
312
|
get!
|
310
313
|
hlink = hlink.to_s if hlink
|
311
|
-
if !hlink || hlink == 'self'
|
314
|
+
if !args && (!hlink || hlink == 'self')
|
312
315
|
_modify(body)
|
313
316
|
self
|
314
317
|
else
|
315
318
|
hl_data = hyperlink[hlink]
|
316
319
|
raise HyperlinkMissing, "#{resource_type} has no #{hlink} hyperlink" unless hl_data
|
317
|
-
hl_res = RemoteResource.new(hl_data['href']
|
320
|
+
hl_res = RemoteResource.new(hl_data['href'], retries: retries, backoff_time: backoff_time,
|
321
|
+
backoff_rate: backoff_rate, backoff_max: backoff_max)
|
318
322
|
hl_res.send :_modify, body, args: args
|
319
323
|
hl_res
|
320
324
|
end
|
@@ -328,13 +332,14 @@ class Api
|
|
328
332
|
def put(hlink=nil, args: nil, body: {})
|
329
333
|
get
|
330
334
|
hlink = hlink.to_s if hlink
|
331
|
-
if !hlink || hlink == 'self'
|
335
|
+
if !args && (!hlink || hlink == 'self')
|
332
336
|
_modify(body) rescue nil
|
333
337
|
self
|
334
338
|
else
|
335
339
|
hl_data = hyperlink[hlink]
|
336
340
|
raise HyperlinkMissing, "#{resource_type} has no #{hlink} hyperlink" unless hl_data
|
337
|
-
hl_res = RemoteResource.new(hl_data['href']
|
341
|
+
hl_res = RemoteResource.new(hl_data['href'], retries: retries, backoff_time: backoff_time,
|
342
|
+
backoff_rate: backoff_rate, backoff_max: backoff_max)
|
338
343
|
hl_res.send :_modify, body, args: args
|
339
344
|
hl_res
|
340
345
|
end
|
@@ -347,7 +352,7 @@ class Api
|
|
347
352
|
#
|
348
353
|
def post!(hlink=nil, args: nil, body: {})
|
349
354
|
get!
|
350
|
-
hlink = (hlink || 'self').to_s
|
355
|
+
hlink = (hlink || !args && 'self').to_s
|
351
356
|
hl_data = hyperlink[hlink]
|
352
357
|
raise HyperlinkMissing, "#{resource_type} has no #{hlink} hyperlink" unless hl_data
|
353
358
|
_create(hl_data['href'], body, args: args)
|
@@ -360,7 +365,7 @@ class Api
|
|
360
365
|
#
|
361
366
|
def post(hlink=nil, args: nil, body: {})
|
362
367
|
get
|
363
|
-
hlink = (hlink || 'self').to_s
|
368
|
+
hlink = (hlink || !args && 'self').to_s
|
364
369
|
hl_data = hyperlink[hlink]
|
365
370
|
raise HyperlinkMissing, "#{resource_type} has no #{hlink} hyperlink" unless hl_data
|
366
371
|
_create(hl_data['href'], body, args: args) rescue nil
|
@@ -433,52 +438,49 @@ class Api
|
|
433
438
|
attr_writer :etag
|
434
439
|
|
435
440
|
|
436
|
-
def
|
441
|
+
def _credentials(rr)
|
437
442
|
if rr.credentials.present? && rr.credentials != Api.credentials(API_USER, API_PASSWORD)
|
438
|
-
credentials
|
439
|
-
token = rr.x_api_token
|
443
|
+
[rr.credentials, rr.x_api_token]
|
440
444
|
else
|
441
|
-
|
442
|
-
token = rr.x_api_token || Api.service_token
|
445
|
+
[nil, rr.x_api_token || Api.service_token]
|
443
446
|
end
|
444
|
-
[credentials, token]
|
445
447
|
end
|
446
448
|
|
447
449
|
|
448
|
-
def
|
449
|
-
credentials, token = _credentials(
|
450
|
-
response = Api.request Api.internalize_uri(
|
450
|
+
def _retrieve#(args: nil)
|
451
|
+
credentials, token = _credentials(self)
|
452
|
+
response = Api.request Api.internalize_uri(uri), :get, args: args,
|
451
453
|
headers: {},
|
452
454
|
credentials: credentials, x_api_token: token,
|
453
|
-
retries:
|
454
|
-
backoff_max:
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
455
|
+
retries: retries, backoff_time: backoff_time, backoff_rate: backoff_rate,
|
456
|
+
backoff_max: backoff_max
|
457
|
+
self.response = response
|
458
|
+
self.status = response.status
|
459
|
+
self.status_message = response.message
|
460
|
+
self.headers = response.headers
|
459
461
|
raise GetFailed, "#{response.status} #{response.message}" unless response.success?
|
460
462
|
begin
|
461
463
|
raw = response.body
|
462
464
|
rescue JSON::ParserError
|
463
465
|
raise UnparseableJson
|
464
466
|
end
|
465
|
-
|
466
|
-
|
467
|
+
_setup raw, response
|
468
|
+
self
|
467
469
|
end
|
468
470
|
|
469
471
|
|
470
472
|
def _conditional_get
|
471
|
-
credentials, token =
|
472
|
-
response = Api.request Api.internalize_uri(uri), :get,
|
473
|
+
credentials, token = _credentials(self)
|
474
|
+
response = Api.request Api.internalize_uri(uri), :get, args: args,
|
473
475
|
headers: {"If-None-Match" => etag},
|
474
476
|
credentials: credentials, x_api_token: token,
|
475
477
|
retries: retries, backoff_time: backoff_time, backoff_rate: backoff_rate,
|
476
478
|
backoff_max: backoff_max
|
477
|
-
|
479
|
+
self.response = response
|
478
480
|
return if response.status == 304
|
479
|
-
|
480
|
-
|
481
|
-
|
481
|
+
self.status = response.status
|
482
|
+
self.status_message = response.message
|
483
|
+
self.headers = response.headers
|
482
484
|
raise ConditionalGetFailed, "#{response.status} #{response.message}" unless response.success?
|
483
485
|
begin
|
484
486
|
raw = response.body
|
@@ -517,7 +519,7 @@ class Api
|
|
517
519
|
|
518
520
|
|
519
521
|
def _modify(body, args: nil)
|
520
|
-
credentials, token =
|
522
|
+
credentials, token = _credentials(self)
|
521
523
|
response = Api.request Api.internalize_uri(uri), :put, headers: {}, body: body.to_json,
|
522
524
|
credentials: credentials, x_api_token: token,
|
523
525
|
retries: retries, backoff_time: backoff_time, backoff_rate: backoff_rate,
|
@@ -542,7 +544,7 @@ class Api
|
|
542
544
|
|
543
545
|
|
544
546
|
def _create(post_uri, body, args: nil)
|
545
|
-
credentials, token =
|
547
|
+
credentials, token = _credentials(self)
|
546
548
|
response = Api.request Api.internalize_uri(post_uri), :post, headers: {}, body: body.to_json,
|
547
549
|
credentials: credentials, x_api_token: token,
|
548
550
|
retries: retries, backoff_time: backoff_time, backoff_rate: backoff_rate,
|
@@ -558,7 +560,8 @@ class Api
|
|
558
560
|
raise UnparseableJson
|
559
561
|
end
|
560
562
|
type, resource = verify_resource(response.body)
|
561
|
-
created = RemoteResource.new(post_uri
|
563
|
+
created = RemoteResource.new(post_uri, retries: retries, backoff_time: backoff_time,
|
564
|
+
backoff_rate: backoff_rate, backoff_max: backoff_max)
|
562
565
|
created.send :_setup, raw, response
|
563
566
|
created.send :etag=, nil
|
564
567
|
created
|
@@ -566,7 +569,7 @@ class Api
|
|
566
569
|
|
567
570
|
|
568
571
|
def _destroy(delete_uri, args: nil)
|
569
|
-
credentials, token =
|
572
|
+
credentials, token = _credentials(self)
|
570
573
|
response = Api.request Api.internalize_uri(delete_uri), :delete, headers: {},
|
571
574
|
credentials: credentials, x_api_token: token,
|
572
575
|
retries: retries, backoff_time: backoff_time, backoff_rate: backoff_rate,
|
data/lib/ocean/version.rb
CHANGED