ocean-rails 4.0.5 → 4.0.7

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: 5349c1dc1cf8eeaf2c770d4e814b545390033d2f
4
- data.tar.gz: 8e6790b74505ad7133671bfe3b7b7c44f2edebcb
3
+ metadata.gz: caa92be6dd839f0a86cc455f0c2a9a6dfd7f9401
4
+ data.tar.gz: 54bcb04237e1e9e28430806718ce2dd16f7f47d5
5
5
  SHA512:
6
- metadata.gz: 1e2081aff6a3aef06d4f7c88c7320c7a27a3d18e64c3615ee19d260c7ca3d372a53c8198c1d9b26e016ffcfc632891bfe9d640a15d852d494ef684162c4e3b72
7
- data.tar.gz: 597f1ab3c2a6dc78aa8d25d68b32d09a11a8b049c7648b232b60637d90603428fe365c75b35446432c176c768695b6626d3295a26d0c528cc7af6a6a19157715
6
+ metadata.gz: 7f87081cbe39166be45ca4c86502d3f955aeacc29c5198be2f1f422c4f3c2f75544eeee81c902af9b2bd3427f2fe4349be1e7a3b1797e9f5e9102433e102095b
7
+ data.tar.gz: 10851d77fc255e898fd6c851355a16cdf262d645d1615c4191546b7916dda9f1cb6799b306a33396e6499fae6fc9d8ca718a0447c39fb6e13c209c0bb72ae6af
@@ -262,16 +262,34 @@ class Api
262
262
  raise Api::TimeoutError, "Api.request timed out" if response.timed_out?
263
263
  raise Api::NoResponseError, "Api.request could not obtain a response" if response.status == 0
264
264
  end
265
- response_getter.call
265
+ response
266
266
  end
267
267
 
268
268
 
269
+ #
270
+ # Api.simultaneously is used for making requests in parallel. For example:
271
+ #
272
+ # results = Api.simultaneously do |r|
273
+ # r << Api.request("http://foo.bar", :get, retries: 3)
274
+ # r << Api.request("http://foo.baz", :get, retries: 3)
275
+ # r << Api.request("http://foo.quux", :get, retries: 3)
276
+ # end
277
+ #
278
+ # The value returned is an array of responses from the Api.request calls. If a request
279
+ # has a post-processor block, the result will not be the response but what the block
280
+ # returns.
281
+ #
282
+ # TimeoutErrors and NoResponseError will not be raised in parallel mode.
283
+ #
284
+ # Only Api.request is supported at the present time. Api::RemoteResource will follow.
285
+ #
269
286
  def self.simultaneously (&block)
270
287
  raise "block required" unless block
271
288
  @inside_simultaneously = true
272
289
  results = []
273
290
  @hydra = nil
274
291
  block.call(results)
292
+ Typhoeus::Config.memoize = true
275
293
  @hydra.run if @hydra
276
294
  results.map(&:call)
277
295
  ensure
@@ -351,11 +369,13 @@ class Api
351
369
  # If not successful, +nil+ is returned.
352
370
  #
353
371
  def self.authenticate(username=API_USER, password=API_PASSWORD)
354
- response = Api.request "/v1/authentications", :post,
355
- headers: {'X-API-Authenticate' => credentials(username, password)}
356
- case response.status
372
+ # response = request "/v1/authentications", :post,
373
+ # headers: {'X-API-Authenticate' => credentials(username, password)}
374
+ response = Typhoeus.post "#{INTERNAL_OCEAN_API_URL}/v1/authentications",
375
+ body: "", headers: {'X-API-Authenticate' => credentials(username, password)}
376
+ case response.code
357
377
  when 201
358
- token = response.body['authentication']['token']
378
+ token = JSON.parse(response.body)['authentication']['token']
359
379
  @service_token = token if username == API_USER && password == API_PASSWORD
360
380
  token
361
381
  when 400
@@ -379,11 +399,6 @@ class Api
379
399
  # authentication. The encoding can be reversed and is intended only to lightly mask the
380
400
  # credentials so that they're not immediately apparent when reading logs.
381
401
  #
382
- def self.encode_credentials(username=nil, password=nil)
383
- ActiveSupport::Deprecation.warn "Api.encode_credentials is deprecated, use Api.credentials instead", caller
384
- credentials username, password
385
- end
386
-
387
402
  def self.credentials(username=nil, password=nil)
388
403
  raise "Only specifying the username is not allowed" if username && !password
389
404
  username ||= API_USER
@@ -174,11 +174,11 @@ class Api
174
174
  end
175
175
 
176
176
  #
177
- # Returns a resource attribute. If the resource isn't present, +get!+ will used to
177
+ # Returns a resource attribute. If the resource isn't present, +get!+ will be used to
178
178
  # retrieve it.
179
179
  #
180
180
  def [](key)
181
- get!
181
+ get! unless present?
182
182
  resource[key]
183
183
  end
184
184
 
@@ -267,8 +267,8 @@ class Api
267
267
  #
268
268
  def self.get(*args)
269
269
  rr = new(*args)
270
- rr.get! rescue nil
271
- rr
270
+ x = rr.get! rescue nil
271
+ x || rr
272
272
  end
273
273
 
274
274
 
@@ -412,11 +412,10 @@ class Api
412
412
  #
413
413
  def refresh!
414
414
  if present? && etag.present?
415
- _conditional_get
415
+ _conditional_get || self
416
416
  else
417
417
  get!
418
418
  end
419
- self
420
419
  end
421
420
 
422
421
  #
@@ -427,11 +426,10 @@ class Api
427
426
  #
428
427
  def refresh
429
428
  if present? && etag.present?
430
- _conditional_get rescue nil
429
+ (_conditional_get rescue nil) || self
431
430
  else
432
431
  get
433
432
  end
434
- self
435
433
  end
436
434
 
437
435
 
@@ -453,11 +451,19 @@ class Api
453
451
 
454
452
  def _retrieve
455
453
  credentials, token = _credentials(self)
456
- response = Api.request Api.internalize_uri(uri), :get, args: args,
457
- headers: {},
458
- credentials: credentials, x_api_token: token,
459
- retries: retries, backoff_time: backoff_time, backoff_rate: backoff_rate,
460
- backoff_max: backoff_max
454
+ response = Api.request(Api.internalize_uri(uri), :get, args: args,
455
+ headers: {},
456
+ credentials: credentials, x_api_token: token,
457
+ retries: retries, backoff_time: backoff_time, backoff_rate: backoff_rate,
458
+ backoff_max: backoff_max) do |x|
459
+ x # Remove this line,
460
+ # _post_retrieve x # uncomment this line,
461
+ end
462
+ _post_retrieve response # and delete this line.
463
+ end
464
+
465
+ def _post_retrieve (response)
466
+ return response if Api.simultaneously?
461
467
  self.response = response
462
468
  self.status = response.status
463
469
  self.status_message = response.message
@@ -469,7 +475,7 @@ class Api
469
475
  raise UnparseableJson
470
476
  end
471
477
  _setup raw, response
472
- self
478
+ #self
473
479
  end
474
480
 
475
481
 
@@ -511,6 +517,7 @@ class Api
511
517
  self.headers = response.headers
512
518
  self.etag = headers['ETag']
513
519
  self.present = true
520
+ self
514
521
  end
515
522
 
516
523
 
@@ -1,3 +1,3 @@
1
1
  module Ocean
2
- VERSION = "4.0.5"
2
+ VERSION = "4.0.7"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ocean-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.5
4
+ version: 4.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Bengtson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-21 00:00:00.000000000 Z
11
+ date: 2014-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: typhoeus