ocean-rails 3.8.2 → 3.8.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3bf3f4a3ed2f020535fd3ae4ab640d2ccf38b8dd
4
- data.tar.gz: e60a238e5ea0f8ecb7637695e96e152f50cc3f69
3
+ metadata.gz: b8016bcce74120528096b71766f7756e0f02b5c6
4
+ data.tar.gz: e6c5b28ce615e5a0b5e479f73d21663359a9f672
5
5
  SHA512:
6
- metadata.gz: c8e439ce945b9e43802153825e69eb91cf4b5ea31c5d0eea0af103b02fad8201ce455f364030d891a4b690284f1ac25a86876fbd0b07d7fa8dfacf3806eb8f06
7
- data.tar.gz: cce20bd75d95089771a74691365bc650ee44295f0cd93e2226cc48882d7b80bbc1790620ab98979f8e38a2a73f849702bd013fee78eb1f02a17722ff3a068bc7
6
+ metadata.gz: 5c63d4c52002d236081bc816a8fe8e57283ac6c2a4ab2f1ec5ddf59448c08ae5918161b54ef0066540fd25436c68b469f8c9c746378469dc8f85fbb1272b6544
7
+ data.tar.gz: b91f6a5a283e7970e481e39cd02a21a512021c6c5acd38edc1cc5d0e2bca0ea952a8579e1a1458c7695d9dfad318887e65ef0c740ac7325a48513e9dcf2f4c22
data/lib/ocean/api.rb CHANGED
@@ -503,6 +503,21 @@ class Api
503
503
  end
504
504
 
505
505
 
506
+ #
507
+ # Constructs a hash suitable as the body of a POST to async_jobs. It lets you set
508
+ # all the allowed attributes, and it also provides a terse shortcut for one-step
509
+ # jobs (by far the most common ones). The following:
510
+ #
511
+ # Api.async_body "/v1/foos", :put
512
+ #
513
+ # is equivalent to
514
+ #
515
+ # Api.async_body steps: [{"url" => "#{INTERNAL_OCEAN_API_URL}/v1/foos"}
516
+ # "method" => "PUT",
517
+ # "body" => {}}]
518
+ #
519
+ # A URL not starting with a / will be internalized.
520
+ #
506
521
  def self.async_job_body(href=nil, method=:get, body: {},
507
522
  credentials: nil,
508
523
  token: nil,
@@ -134,6 +134,12 @@ class Api
134
134
  attr_reader :raw, :resource, :resource_type, :status, :headers, :credentials, :x_api_token
135
135
  attr_reader :status_message, :response, :etag
136
136
 
137
+ #
138
+ # The credentials and the x_api_token, if both are left unspecified, will default to
139
+ # the local credentials and service token. If both are specified and different from
140
+ # the default values, they will be used instead. Specifying only one of them is not
141
+ # permitted.
142
+ #
137
143
  def initialize(uri, type="application/json",
138
144
  credentials: nil, x_api_token: nil,
139
145
  retries: 3, backoff_time: 1, backoff_rate: 0.9, backoff_max: 30)
@@ -155,47 +161,105 @@ class Api
155
161
  @x_api_token = x_api_token
156
162
  end
157
163
 
164
+ #
165
+ # True if the resource has been read successfully.
166
+ #
158
167
  def present?
159
168
  @present
160
169
  end
161
170
 
162
-
171
+ #
172
+ # Returns a resource attribute. If the resource isn't present, +get!+ will used to
173
+ # retrieve it.
174
+ #
163
175
  def [](key)
164
176
  get!
165
177
  resource[key]
166
178
  end
167
179
 
180
+ #
181
+ # Sets a resource attribute. The resource will not be retrieved if not present.
182
+ #
168
183
  def []=(key, value)
169
184
  resource[key] = value
170
185
  end
171
186
 
187
+ #
188
+ # Returns the hash of hyperlinks. The resource will not be retrieved if not present.
189
+ #
172
190
  def hyperlink
173
191
  self['_links']
174
192
  end
175
193
 
194
+ #
195
+ # Returns resources own href. The resource will not be retrieved if not present.
196
+ #
176
197
  def href
177
198
  hyperlink['self']['href']
178
199
  end
179
200
 
201
+ #
202
+ # Returns resources own content type. The resource will not be retrieved if not present.
203
+ #
180
204
  def type
181
205
  hyperlink['self']['type']
182
206
  end
183
207
 
184
-
208
+ #
209
+ # Raised when a POST fails, i.e. the response status isn't 2xx.
210
+ #
185
211
  class PostFailed < StandardError; end
212
+
213
+ #
214
+ # Raised when a GET fails, i.e. the response status isn't 2xx.
215
+ #
186
216
  class GetFailed < StandardError; end
217
+
218
+ #
219
+ # Raised when a Conditional GET fails, i.e. the response status isn't 2xx.
220
+ #
221
+ class ConditionalGetFailed < StandardError; end
222
+
223
+ #
224
+ # Raised when a PUT fails, i.e. the response status isn't 2xx.
225
+ #
187
226
  class PutFailed < StandardError; end
227
+
228
+ #
229
+ # Raised when a DELETE fails, i.e. the response status isn't 2xx.
230
+ #
188
231
  class DeleteFailed < StandardError; end
232
+
233
+ #
234
+ # Raised when a POST, GET, or PUT doesn't return JSON or when the returned JSON
235
+ # doesn't parse.
236
+ #
189
237
  class UnparseableJson < StandardError; end
238
+
239
+ #
240
+ # Raised when what a POST, GET, or PUT returns parses correctly but isn't an
241
+ # Ocean resource in the proper format.
242
+ #
190
243
  class JsonIsNoResource < StandardError; end
244
+
245
+ #
246
+ # Raised when a specified hyperlink doesn't exist in the resource representation.
247
+ #
191
248
  class HyperlinkMissing < StandardError; end
192
- class ConditionalGetFailed < StandardError; end
193
249
 
194
250
 
251
+ #
252
+ # Class method to retrieve a resource. Will raise exceptions if problems occur,
253
+ # otherwise returns the resource itself. The args are passed directly to +new+.
254
+ #
195
255
  def self.get!(*args)
196
256
  _retrieve new(*args)
197
257
  end
198
258
 
259
+ #
260
+ # Class method to retrieve a resource. Will not raise exceptions if problems occur,
261
+ # but will always return the resource itself. The args are passed directly to +new+.
262
+ #
199
263
  def self.get(*args)
200
264
  rr = new(*args)
201
265
  rr.get! rescue nil
@@ -203,6 +267,10 @@ class Api
203
267
  end
204
268
 
205
269
 
270
+ #
271
+ # Instance method to GET a resource or any of its hyperlinks. Will raise exceptions
272
+ # if they occur, otherwise will return the resource itself.
273
+ #
206
274
  def get!(hlink=nil)
207
275
  RemoteResource._retrieve self unless present?
208
276
  hlink = hlink.to_s if hlink
@@ -215,6 +283,11 @@ class Api
215
283
  end
216
284
  end
217
285
 
286
+ #
287
+ # Instance method to GET a resource or any of its hyperlinks. Will not raise
288
+ # exceptions if problems occur, but will always return the resource itself.
289
+ # A missing hyperlink, though, will always raise a HyperlinkMissing exception.
290
+ #
218
291
  def get(hlink=nil)
219
292
  get! rescue nil
220
293
  hlink = hlink.to_s if hlink
@@ -228,6 +301,10 @@ class Api
228
301
  end
229
302
 
230
303
 
304
+ #
305
+ # Instance method to do a PUT to a resource or any of its hyperlinks. Will raise exceptions
306
+ # if they occur, otherwise will return the resource itself.
307
+ #
231
308
  def put!(hlink=nil, body: {})
232
309
  get!
233
310
  hlink = hlink.to_s if hlink
@@ -243,6 +320,11 @@ class Api
243
320
  end
244
321
  end
245
322
 
323
+ #
324
+ # Instance method to do a PUT to a resource or any of its hyperlinks. Will not raise
325
+ # exceptions if they occur, but will always return the resource itself.
326
+ # A missing hyperlink, though, will always raise a HyperlinkMissing exception.
327
+ #
246
328
  def put(hlink=nil, body: {})
247
329
  get
248
330
  hlink = hlink.to_s if hlink
@@ -259,6 +341,10 @@ class Api
259
341
  end
260
342
 
261
343
 
344
+ #
345
+ # Instance method to do a POST to a resource or any of its hyperlinks. Will raise exceptions
346
+ # if they occur, otherwise will return the resource itself.
347
+ #
262
348
  def post!(hlink=nil, body: {})
263
349
  get!
264
350
  hlink = (hlink || 'self').to_s
@@ -267,6 +353,11 @@ class Api
267
353
  _create(hl_data['href'], body)
268
354
  end
269
355
 
356
+ #
357
+ # Instance method to do a POST to a resource or any of its hyperlinks. Will not raise
358
+ # exceptions if they occur, but will always return the resource itself.
359
+ # A missing hyperlink, though, will always raise a HyperlinkMissing exception.
360
+ #
270
361
  def post(hlink=nil, body: {})
271
362
  get
272
363
  hlink = (hlink || 'self').to_s
@@ -276,6 +367,10 @@ class Api
276
367
  end
277
368
 
278
369
 
370
+ #
371
+ # Instance method to do a DELETE to a resource or any of its hyperlinks. Will raise exceptions
372
+ # if they occur, otherwise will return the resource itself.
373
+ #
279
374
  def delete!(hlink=nil)
280
375
  get!
281
376
  hlink = (hlink || 'self').to_s
@@ -285,6 +380,11 @@ class Api
285
380
  self
286
381
  end
287
382
 
383
+ #
384
+ # Instance method to do a DELETE to a resource or any of its hyperlinks. Will not raise
385
+ # exceptions if they occur, but will always return the resource itself.
386
+ # A missing hyperlink, though, will always raise a HyperlinkMissing exception.
387
+ #
288
388
  def delete(hlink=nil)
289
389
  get
290
390
  hlink = (hlink || 'self').to_s
@@ -295,6 +395,12 @@ class Api
295
395
  end
296
396
 
297
397
 
398
+ #
399
+ # If the resource is present and has received an ETag in previous requests,
400
+ # will perform a Conditional GET to update the local representation. If the resource
401
+ # isn't present or has no ETag, a normal +#get!+ will be done. If no exception is
402
+ # raised, the resource itself is returned.
403
+ #
298
404
  def refresh!
299
405
  if present? && etag.present?
300
406
  _conditional_get
@@ -304,6 +410,12 @@ class Api
304
410
  self
305
411
  end
306
412
 
413
+ #
414
+ # If the resource is present and has received an ETag in previous requests,
415
+ # will perform a Conditional GET to update the local representation. If the resource
416
+ # isn't present or has no ETag, a normal +#get+ will be done. The resource will
417
+ # always be returned.
418
+ #
307
419
  def refresh
308
420
  if present? && etag.present?
309
421
  _conditional_get rescue nil
data/lib/ocean/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ocean
2
- VERSION = "3.8.2"
2
+ VERSION = "3.8.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ocean-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.8.2
4
+ version: 3.8.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Bengtson