ocean-rails 4.0.4 → 4.0.5

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: 9e13cc2480ac989b37242e14182c41931b25b5ff
4
- data.tar.gz: e84d495747487e35a951cc80eb1c53508d742351
3
+ metadata.gz: 5349c1dc1cf8eeaf2c770d4e814b545390033d2f
4
+ data.tar.gz: 8e6790b74505ad7133671bfe3b7b7c44f2edebcb
5
5
  SHA512:
6
- metadata.gz: c75d7190f2c20ada7c2349e625523fb2bf5161bd7e805d680d5bd4b2872605850fa3e65cd067022aad9f2ad3b18be0e0203c4b9215839df3d1c716562594a2ae
7
- data.tar.gz: 17e85cd0ce7257bbedac4b231e4222f62e563bc21089ee43a29c448f68314ea94f41e82a175d04417f3065953b4295f8c36958bd4d469df8ea9b8050b3596925
6
+ metadata.gz: 1e2081aff6a3aef06d4f7c88c7320c7a27a3d18e64c3615ee19d260c7ca3d372a53c8198c1d9b26e016ffcfc632891bfe9d640a15d852d494ef684162c4e3b72
7
+ data.tar.gz: 597f1ab3c2a6dc78aa8d25d68b32d09a11a8b049c7648b232b60637d90603428fe365c75b35446432c176c768695b6626d3295a26d0c528cc7af6a6a19157715
data/lib/ocean/api.rb CHANGED
@@ -181,11 +181,13 @@ class Api
181
181
  headers['X-API-Token'] = x_api_token if x_api_token.present?
182
182
  headers['X-Metadata'] = x_metadata if x_metadata.present?
183
183
 
184
- retries = 0 unless http_method.to_s.upcase == "GET"
184
+ retries = 0 unless ["GET", "HEAD"].include? http_method.to_s.upcase
185
185
 
186
186
  @hydra ||= Typhoeus::Hydra.hydra
187
- request = nil # For clarity
187
+
188
+ request = nil
188
189
  response = nil
190
+ response_getter = lambda { response }
189
191
 
190
192
  url = url.first == "/" ? "#{INTERNAL_OCEAN_API_URL}#{url}" : Api.internalize_uri(url)
191
193
 
@@ -199,18 +201,18 @@ class Api
199
201
  body: body,
200
202
  ssl_verifypeer: ssl_verifypeer,
201
203
  ssl_verifyhost: ssl_verifyhost)
202
-
203
204
  # Define a callback to process the response and do retries
204
205
  request.on_complete do |typhoeus_response|
205
- response = Response.new(typhoeus_response)
206
+ response = Response.new typhoeus_response
206
207
  case response.status
207
208
  when 100..199
208
209
  enqueue_request.call # Ignore and retry
209
210
  when 200..299, 304
210
- # Success, call the post-processor if any
211
- if block
212
- response = block.call response
213
- end
211
+ # Success, call the post-processor if any. Any further Api.request
212
+ # calls done by the post-processor will use the same response
213
+ # accessors, which means the final result will be what the last
214
+ # post-processor to finish returns.
215
+ response = block.call(response) if block
214
216
  when 300..399
215
217
  nil # Done, redirect
216
218
  when 400, 419
@@ -231,11 +233,11 @@ class Api
231
233
  when 400..499
232
234
  nil # Done, fail
233
235
  else
234
- # Retry if there are any retries left
236
+ # We got a 5xx. Retry if there are any retries left
235
237
  if retries > 0
236
238
  retries -= 1
237
239
  sleep backoff_time
238
- backoff_time = [backoff_time + backoff_time * backoff_rate, 30].min
240
+ backoff_time = [backoff_time + backoff_time * backoff_rate, backoff_max].min
239
241
  enqueue_request.call
240
242
  else
241
243
  nil # Done, don't retry
@@ -251,27 +253,27 @@ class Api
251
253
 
252
254
  # So create and enqueue the request
253
255
  enqueue_request.call
254
- # Run it, unless we're accumulating calls inside an Api.simultaneously block
255
- unless @inside_simultaneously
256
- # The next line blocks until completed, possibly after several retries
257
- @hydra.run
258
- if response.is_a?(Response)
259
- # Raise any exceptions
260
- raise Api::TimeoutError, "Api.request timed out" if response.timed_out?
261
- raise Api::NoResponseError, "Api.request could not obtain a response" if response.status == 0
262
- end
263
- return response
256
+ # If doing parallel calls, return a lambda which returns the final response
257
+ return response_getter if Api.simultaneously?
258
+ # Run it now. Blocks until completed, possibly after any number of retries
259
+ @hydra.run
260
+ if response.is_a?(Response)
261
+ # Raise any exceptions
262
+ raise Api::TimeoutError, "Api.request timed out" if response.timed_out?
263
+ raise Api::NoResponseError, "Api.request could not obtain a response" if response.status == 0
264
264
  end
265
- # Return nil: we have no response yet
266
- nil
265
+ response_getter.call
267
266
  end
268
267
 
269
268
 
270
269
  def self.simultaneously (&block)
271
270
  raise "block required" unless block
272
271
  @inside_simultaneously = true
272
+ results = []
273
273
  @hydra = nil
274
- block.call
274
+ block.call(results)
275
+ @hydra.run if @hydra
276
+ results.map(&:call)
275
277
  ensure
276
278
  @inside_simultaneously = false
277
279
  end
@@ -163,6 +163,7 @@ class Api
163
163
  @headers = nil
164
164
  @credentials = credentials
165
165
  @x_api_token = x_api_token
166
+ @collection = false
166
167
  end
167
168
 
168
169
  #
data/lib/ocean/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ocean
2
- VERSION = "4.0.4"
2
+ VERSION = "4.0.5"
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.4
4
+ version: 4.0.5
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-15 00:00:00.000000000 Z
11
+ date: 2014-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: typhoeus
@@ -283,7 +283,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
283
283
  version: '0'
284
284
  requirements: []
285
285
  rubyforge_project:
286
- rubygems_version: 2.2.1
286
+ rubygems_version: 2.2.2
287
287
  signing_key:
288
288
  specification_version: 4
289
289
  summary: This gem implements common Ocean behaviour for Ruby and Ruby on Rails.