ocean-rails 6.1.7 → 6.1.8

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ocean/api.rb +32 -22
  3. data/lib/ocean/version.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a68d0d48e09ae7bee67dc8099da9ed592b095b94
4
- data.tar.gz: 7aff7c2a33add1f11ab9da72ff4047d884d1bfe1
3
+ metadata.gz: a7db358dd02e5c6518a773461ca0d22b6123b0e8
4
+ data.tar.gz: 72830f4405a9d35e22693795de20d3bbb211be22
5
5
  SHA512:
6
- metadata.gz: d888abd3a67b2fc421e722908ebcb6350754649aa846a143f59c074e77b32dce1ba37db487ca0551b36a417a573bc48026967d9d571acbb1867322b3a7eba039
7
- data.tar.gz: acda4d43fb7242703781fb9f742e3ca0d98f8f010611e616901234040885b5300dc13fc3fb644c3bd9cb8f7023719365785661e191ae722c18a3bcbf56b186e0
6
+ metadata.gz: 2a9d574e20a145ecc738b0e7566ade9de5608505d64de0cb49391e8262e8723846f1ef4f5f6ff117caee49ba0b146fe5e767934ef7235a62c2789bb36ef58c02
7
+ data.tar.gz: 9e8f1cf62eabfcc3d297eb16392e1e79d25a523cdff38b279faf212be072edb72c8d9528322f15183a5491231193da55f37c9e33158209b92c8d59b557ab95bf
data/lib/ocean/api.rb CHANGED
@@ -202,7 +202,7 @@ class Api
202
202
 
203
203
  url = url.first == "/" ? "#{INTERNAL_OCEAN_API_URL}#{url}" : Api.internalize_uri(url)
204
204
 
205
- # This is a Proc when run queues the request and schedules retries
205
+ # This is a Proc which when run queues the request and schedules retries
206
206
  enqueue_request = lambda do
207
207
  # First construct a request. It will not be sent yet.
208
208
  request = Typhoeus::Request.new(url,
@@ -379,27 +379,37 @@ class Api
379
379
  # If not successful, +nil+ is returned.
380
380
  #
381
381
  def self.authenticate(username=API_USER, password=API_PASSWORD)
382
- # response = request "/v1/authentications", :post,
383
- # headers: {'X-API-Authenticate' => credentials(username, password)}
384
- response = Typhoeus.post "#{INTERNAL_OCEAN_API_URL}/v1/authentications",
385
- body: "", headers: {'X-API-Authenticate' => credentials(username, password)}
386
- case response.code
387
- when 201
388
- token = JSON.parse(response.body)['authentication']['token']
389
- @service_token = token if username == API_USER && password == API_PASSWORD
390
- token
391
- when 400
392
- # Malformed credentials. Don't repeat the request.
393
- nil
394
- when 403
395
- # Does not authenticate. Don't repeat the request.
396
- nil
397
- when 500
398
- # Error. Don't repeat.
399
- nil
400
- else
401
- # Should never end up here.
402
- raise "Authentication weirdness"
382
+ attempts = 3
383
+ loop do
384
+ response = Typhoeus.post "#{INTERNAL_OCEAN_API_URL}/v1/authentications",
385
+ body: "", headers: {'X-API-Authenticate' => credentials(username, password)}
386
+ case response.code
387
+ when 100..199
388
+ return nil if attempts < 1
389
+ attempts -= 1
390
+ next
391
+ when 200..299
392
+ token = JSON.parse(response.body)['authentication']['token']
393
+ @service_token = token if username == API_USER && password == API_PASSWORD
394
+ return token
395
+ when 403
396
+ # Does not authenticate. Don't repeat the request.
397
+ return nil
398
+ when 400
399
+ # Malformed credentials. Don't repeat the request.
400
+ return nil
401
+ when 400..499
402
+ # Client error. Don't repeat the request.
403
+ return nil
404
+ when 500
405
+ # Error. Don't repeat.
406
+ return nil if attempts < 1
407
+ attempts -= 1
408
+ next
409
+ else
410
+ # Should never end up here.
411
+ raise "Authentication weirdness"
412
+ end
403
413
  end
404
414
  end
405
415
 
data/lib/ocean/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ocean
2
- VERSION = "6.1.7"
2
+ VERSION = "6.1.8"
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: 6.1.7
4
+ version: 6.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Bengtson