shopify_api_extensions 0.1.1 → 0.1.2

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: 7566570d57f4f468edcdc70d4f775b378966f62a
4
- data.tar.gz: f00c3ffbe99977f67e78ee8e4b65cd493050307d
3
+ metadata.gz: c941b2d40cd938d27a81562e21d5e1cc24254939
4
+ data.tar.gz: ebb922c0292452b14f44f997b49df06b24a1ae36
5
5
  SHA512:
6
- metadata.gz: f28fe3ae813e604ec37bf50279d3d00846ec0ef9a54550425e439628d07d43ff400f5ac6a7d557d0cb116ee756f86581e074df2f64a2430bfa92f07d6a54e83d
7
- data.tar.gz: 4da2d68bb217749870b4ae6c58a833f20c1bb5e823863b668f89496249b50e45e6bcec74b6faa028611c0e045ac627dd2a4dcacb1f03c35ceaa9da34dfa053fa
6
+ metadata.gz: 44917662ae3ff68b7b25d3aa478099220a0125d784a13d239ddcebf9e36acead1915a1e507b4406a6e6b25a3d1378bb1d062f11c86e2b8b2201713ecfebec5f7
7
+ data.tar.gz: 69f0effd50de8174f283dc08ee0d16f991fb4ac3fae03ebe0dfaee1e6a992ea1574f71c713cc0992084d0c5cde4ffaab5299cb640a50b4892557ed6588e325e7
data/README.md CHANGED
@@ -25,6 +25,8 @@ gem 'shopify_api_extensions'
25
25
  ShopifyAPI::Product.auto_paging_each do |product|
26
26
  puts "#{product.id}"
27
27
  end
28
+
29
+ ShopifyAPI::Order.list(limit: 100).map(&:number)
28
30
  ```
29
31
 
30
32
  ## Development
@@ -2,11 +2,13 @@ ShopifyAPI::Connection.class_eval do
2
2
  alias_method :shopify_request, :request
3
3
 
4
4
  def request(*args)
5
- count = 0
6
- limit = 10
5
+ network_retry = 0
6
+ network_limit = 10
7
+
8
+ rate_limit_retry = 0
9
+ rate_limit_limit = 30
7
10
 
8
11
  begin
9
- count += 1
10
12
  shopify_request(*args)
11
13
  rescue Exception => e
12
14
  exceptions_to_retry = [
@@ -16,18 +18,37 @@ ShopifyAPI::Connection.class_eval do
16
18
  Errno::EHOSTUNREACH,
17
19
  EOFError,
18
20
  Zlib::BufError,
19
- SocketError
21
+ SocketError,
22
+ ActiveResource::SSLError,
23
+ # NOTE represents only 500x errors
24
+ ActiveResource::ServerError
20
25
  ]
21
26
 
22
27
  if !exceptions_to_retry.include?(e.class)
23
28
  raise
24
29
  end
25
30
 
26
- # TODO look at code instead of static string? This is brittle
27
- if count >= limit || (e.class == ActiveResource::ClientError && e.message != "Failed. Response code = 429. Response message = Too Many Requests.")
31
+ if e.class == ActiveResource::ClientError && e.message =~ /429/ && e.message =~ /Too Many Requests/
32
+ if rate_limit_retry > 0 && rate_limit_retry % 10 == 0
33
+ puts "Shopify Rate Limit Error Encountered"
34
+ end
35
+
36
+ if rate_limit_retry >= rate_limit_limit
37
+ raise
38
+ else
39
+ rate_limit_retry += 1
40
+ sleep(rate_limit_retry)
41
+ retry
42
+ end
43
+ elsif e.class == ActiveResource::ClientError
44
+ raise
45
+ end
46
+
47
+ if network_retry >= network_limit
28
48
  raise
29
49
  else
30
- sleep(count)
50
+ network_retry += 1
51
+ sleep(network_retry)
31
52
  retry
32
53
  end
33
54
  end
@@ -1,3 +1,3 @@
1
1
  module ShopifyAPIExtensions
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shopify_api_extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Bianco
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-05-11 00:00:00.000000000 Z
11
+ date: 2017-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: shopify_api