active_fulfillment 3.0.0.pre3 → 3.0.0.pre4

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: 6d45dc280f777d4353c5ac75310d2d797e418430
4
- data.tar.gz: ffb69cd6def6034c48906a9cc7621be44e788185
3
+ metadata.gz: ff356b4c8f350a78ca0475c4415257fa803f83a9
4
+ data.tar.gz: 971bb598f5bd8ff27cb73eb0e0c5810453586714
5
5
  SHA512:
6
- metadata.gz: 9bf1e4dd980b394918d515bbe8ca11e142b544cda990e0f8c89501bb81d8a6b6a736c1dca95921da98a2eb0d86fe3be322b2d26e43ff23c67aefcf1bac8efe85
7
- data.tar.gz: 81ba7cee54bd6844018dcd5ce5313bf52a572d6cbce202fcfc5f19067a95534e75c5551a8ceff1f9e1b40265f472f4cbd05c8b96a1d3bb7fae1ac5fecfe0557f
6
+ metadata.gz: 2d7ce7cbb4a2dd194df82e42f7677678e92ccecfa5b01b7f9990622252bfaac22cb2b8542fdb3f55c5c6a553ff35e4e460cf223087ccb1f070fc71ef136a451f
7
+ data.tar.gz: d1632004e3c03275a02bd0f1c2eabdef9cede7ca047fa75523d34a581d3ebc87466194d8701d2aa2c162fa092d1240b3a3c5f2e3be69aa782df284b85ebaf9c4
@@ -150,17 +150,20 @@ module ActiveFulfillment
150
150
  end
151
151
 
152
152
  def fetch_tracking_data(order_ids, options = {})
153
+ index = 0
153
154
  order_ids.reduce(nil) do |previous, order_id|
154
- response = commit :post, :outbound, :tracking, build_tracking_request(order_id, options)
155
- return response if !response.success?
156
-
157
- if previous
158
- response.tracking_numbers.merge!(previous.tracking_numbers)
159
- response.tracking_companies.merge!(previous.tracking_companies)
160
- response.tracking_urls.merge!(previous.tracking_urls)
161
- end
155
+ index += 1
156
+ response = commit :post, :outbound, :tracking, build_tracking_request(order_id, options)
157
+ return response if !response.success?
158
+
159
+ if previous
160
+ sleep_for_throttle_options(options[:throttle], index)
161
+ response.tracking_numbers.merge!(previous.tracking_numbers)
162
+ response.tracking_companies.merge!(previous.tracking_companies)
163
+ response.tracking_urls.merge!(previous.tracking_urls)
164
+ end
162
165
 
163
- response
166
+ response
164
167
  end
165
168
  end
166
169
 
@@ -460,6 +463,11 @@ module ActiveFulfillment
460
463
 
461
464
  private
462
465
 
466
+ def sleep_for_throttle_options(throttle_options, index)
467
+ return unless interval = throttle_options.try(:[], :interval)
468
+ sleep(throttle_options[:sleep_time]) if (index % interval).zero?
469
+ end
470
+
463
471
  def secure_compare(a, b)
464
472
  return false unless a.bytesize == b.bytesize
465
473
 
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module ActiveFulfillment
3
- VERSION = "3.0.0.pre3"
3
+ VERSION = "3.0.0.pre4"
4
4
  end
@@ -381,6 +381,22 @@ class AmazonMarketplaceWebServiceTest < Minitest::Test
381
381
  assert_equal %w{93ZZ00}, response.tracking_numbers['extern_id_1154539615776']
382
382
  end
383
383
 
384
+ def test_fetch_tracking_numbers_with_throttle
385
+ @service.expects(:ssl_post).times(30).returns(xml_fixture('amazon_mws/fulfillment_get_fulfillment_order'))
386
+ numbers = (1..30).map {|i| "extern_id_#{i}" }
387
+ @service.expects(:sleep).times(3)
388
+ response = @service.fetch_tracking_numbers(numbers, {throttle: {interval: 10, sleep_time: 1}})
389
+ assert response.success?
390
+ end
391
+
392
+ def test_fetch_tracking_numbers_with_throttle_for_not_enough_requests
393
+ @service.expects(:ssl_post).times(5).returns(xml_fixture('amazon_mws/fulfillment_get_fulfillment_order'))
394
+ numbers = (1..5).map {|i| "extern_id_#{i}" }
395
+ @service.expects(:sleep).never
396
+ response = @service.fetch_tracking_numbers(numbers, {throttle: {interval: 10, sleep_time: 1}})
397
+ assert response.success?
398
+ end
399
+
384
400
  def test_fetch_tracking_numbers_aborts_on_error
385
401
  response = mock('response')
386
402
  response.stubs(:code).returns(500)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_fulfillment
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.pre3
4
+ version: 3.0.0.pre4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cody Fauser
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-08-26 00:00:00.000000000 Z
12
+ date: 2015-09-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport