shopify_api_retry 0.0.1
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 +7 -0
- data/.gitignore +59 -0
- data/.travis.yml +7 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +37 -0
- data/Rakefile +1 -0
- data/lib/shopify_api_retry.rb +40 -0
- data/shopify_api_retry.gemspec +25 -0
- metadata +95 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9f6d412f4f64e2d2ac4d7e741008526b7a71b767
|
4
|
+
data.tar.gz: 1db395165fe1466210334c70efb1db523242837b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 871762fa4d151434d30a088cdaad6c2e2da6d5207b3a2671fe0e7ee1076b9f1b7a179e238596841463eb9dbde4023e4d0c542ae350dfd06f7d85cce6b87226c6
|
7
|
+
data.tar.gz: b0d9c33fbf726213a3eba185df8dac8839539a29867c53a15b5730dd535946efbd4f19bac143788c4084f17cec0bcbac9a35edaecf19369edd5ee6f49ebb2e09
|
data/.gitignore
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
|
2
|
+
# Created by https://www.gitignore.io/api/ruby
|
3
|
+
# Edit at https://www.gitignore.io/?templates=ruby
|
4
|
+
|
5
|
+
### Ruby ###
|
6
|
+
*.gem
|
7
|
+
*.rbc
|
8
|
+
/.config
|
9
|
+
/coverage/
|
10
|
+
/InstalledFiles
|
11
|
+
/pkg/
|
12
|
+
/spec/reports/
|
13
|
+
/spec/examples.txt
|
14
|
+
/test/tmp/
|
15
|
+
/test/version_tmp/
|
16
|
+
/tmp/
|
17
|
+
|
18
|
+
# Used by dotenv library to load environment variables.
|
19
|
+
# .env
|
20
|
+
|
21
|
+
# Ignore Byebug command history file.
|
22
|
+
.byebug_history
|
23
|
+
|
24
|
+
## Specific to RubyMotion:
|
25
|
+
.dat*
|
26
|
+
.repl_history
|
27
|
+
build/
|
28
|
+
*.bridgesupport
|
29
|
+
build-iPhoneOS/
|
30
|
+
build-iPhoneSimulator/
|
31
|
+
|
32
|
+
## Specific to RubyMotion (use of CocoaPods):
|
33
|
+
#
|
34
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
35
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
36
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
37
|
+
# vendor/Pods/
|
38
|
+
|
39
|
+
## Documentation cache and generated files:
|
40
|
+
/.yardoc/
|
41
|
+
/_yardoc/
|
42
|
+
/doc/
|
43
|
+
/rdoc/
|
44
|
+
|
45
|
+
## Environment normalization:
|
46
|
+
/.bundle/
|
47
|
+
/vendor/bundle
|
48
|
+
/lib/bundler/man/
|
49
|
+
|
50
|
+
# for a library or gem, you might want to ignore these files since the code is
|
51
|
+
# intended to run in multiple environments; otherwise, check them in:
|
52
|
+
Gemfile.lock
|
53
|
+
# .ruby-version
|
54
|
+
# .ruby-gemset
|
55
|
+
|
56
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
57
|
+
.rvmrc
|
58
|
+
|
59
|
+
# End of https://www.gitignore.io/api/ruby
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright 2016 - 2019 (c) ScreenStaring
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# ShopifyAPIRetry
|
2
|
+
|
3
|
+
Simple module to retry a [ShopifyAPI](https://github.com/Shopify/shopify_api) request if an HTTP 429 (too many requests) is returned. No monkey patching.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
```rb
|
8
|
+
ShopifyAPIRetry.retry { customer.update_attribute(:tags, "foo") }
|
9
|
+
ShopifyAPIRetry.retry(30) { customer.update_attribute(:tags, "foo") } # Retry after 30 seconds on HTTP 429
|
10
|
+
customer = ShopifyAPIRetry.retry { ShopifyAPI::Customer.find(id) }
|
11
|
+
```
|
12
|
+
|
13
|
+
If no retry time is provided the value of the HTTP header `Retry-After` is used. If it's not given (it always is) `2` is used.
|
14
|
+
|
15
|
+
If the retry fails the original error is raised (`ActiveResource::ClientError` or subclass).
|
16
|
+
|
17
|
+
## Installation
|
18
|
+
|
19
|
+
Bundler:
|
20
|
+
|
21
|
+
```rb
|
22
|
+
gem "shopify_api_retry"
|
23
|
+
```
|
24
|
+
|
25
|
+
Gem:
|
26
|
+
|
27
|
+
```
|
28
|
+
gem install shopify_api_retry
|
29
|
+
```
|
30
|
+
|
31
|
+
## License
|
32
|
+
|
33
|
+
Released under the MIT License: www.opensource.org/licenses/MIT
|
34
|
+
|
35
|
+
---
|
36
|
+
|
37
|
+
Made by [ScreenStaring](http://screenstaring.com)
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require "shopify_api"
|
2
|
+
|
3
|
+
module ShopifyAPIRetry
|
4
|
+
VERSION = "0.0.1".freeze
|
5
|
+
HTTP_RETRY_AFTER = "Retry-After".freeze
|
6
|
+
|
7
|
+
#
|
8
|
+
# Execute the provided block. If an HTTP 429 response is return try
|
9
|
+
# it again. If no retry time is provided the value of the HTTP header <code>Retry-After</code>
|
10
|
+
# is used. If it's not given (it always is) +2+ is used.
|
11
|
+
#
|
12
|
+
# If retry fails the original error is raised (`ActiveResource::ClientError` or subclass).
|
13
|
+
#
|
14
|
+
# Returns the value of the block.
|
15
|
+
#
|
16
|
+
def retry(seconds_to_wait = nil)
|
17
|
+
raise ArgumentError, "block required" unless block_given?
|
18
|
+
raise ArgumentError, "seconds to wait must be > 0" unless seconds_to_wait.nil? || seconds_to_wait > 0
|
19
|
+
|
20
|
+
result = nil
|
21
|
+
retried = false
|
22
|
+
|
23
|
+
begin
|
24
|
+
result = yield
|
25
|
+
rescue ActiveResource::ClientError => e
|
26
|
+
# Not 100% if we need to check for code method, I think I saw a NoMethodError...
|
27
|
+
raise unless !retried && e.response.respond_to?(:code) && e.response.code.to_i == 429
|
28
|
+
|
29
|
+
seconds_to_wait = (e.response[HTTP_RETRY_AFTER] || 2).to_i unless seconds_to_wait
|
30
|
+
sleep seconds_to_wait
|
31
|
+
|
32
|
+
retried = true
|
33
|
+
retry
|
34
|
+
end
|
35
|
+
|
36
|
+
result
|
37
|
+
end
|
38
|
+
|
39
|
+
module_function :retry
|
40
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = "shopify_api_retry"
|
3
|
+
spec.version = "0.0.1"
|
4
|
+
spec.authors = ["Skye Shaw"]
|
5
|
+
spec.email = ["skye.shaw@gmail.com"]
|
6
|
+
|
7
|
+
spec.summary = %q{Retry a ShopifyAPI request if an HTTP 429 (too many requests) is returned}
|
8
|
+
spec.description = %q{Simple module to retry a ShopifyAPI request if an HTTP 429 (too many requests) is returned. No monkey patching.}
|
9
|
+
spec.homepage = "https://github.com/ScreenStaring/shopify_api_retry"
|
10
|
+
spec.license = "MIT"
|
11
|
+
|
12
|
+
# Specify which files should be added to the gem when it is released.
|
13
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
14
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
15
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
16
|
+
end
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "shopify_api", ">= 4.0"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: shopify_api_retry
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Skye Shaw
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-07-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: shopify_api
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.16'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.16'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
description: Simple module to retry a ShopifyAPI request if an HTTP 429 (too many
|
56
|
+
requests) is returned. No monkey patching.
|
57
|
+
email:
|
58
|
+
- skye.shaw@gmail.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- lib/shopify_api_retry.rb
|
70
|
+
- shopify_api_retry.gemspec
|
71
|
+
homepage: https://github.com/ScreenStaring/shopify_api_retry
|
72
|
+
licenses:
|
73
|
+
- MIT
|
74
|
+
metadata: {}
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 2.6.14
|
92
|
+
signing_key:
|
93
|
+
specification_version: 4
|
94
|
+
summary: Retry a ShopifyAPI request if an HTTP 429 (too many requests) is returned
|
95
|
+
test_files: []
|