shopify_api_rate_limiter 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/Gemfile +3 -0
- data/README.md +7 -0
- data/Rakefile +2 -0
- data/lib/shopify_api_rate_limiter.rb +20 -0
- data/lib/shopify_api_rate_limiter/active_resource/connection.rb +7 -0
- data/lib/shopify_api_rate_limiter/engine.rb +5 -0
- data/lib/shopify_api_rate_limiter/throttled_connection.rb +30 -0
- data/lib/shopify_api_rate_limiter/version.rb +3 -0
- data/shopify_api_rate_limiter.gemspec +22 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e2804a85d4d550041386b466d6afd473490a403d
|
4
|
+
data.tar.gz: 69d21214df61574234c0b413af972a8f69cfadbe
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9d34ff220e9d9edf3358f30bf369818a8b3e5d52a1061401210fab0dce6d8e7ae8b76bcd1132f790f7de283bb3574e36e46fa25bf16bc957621ff0b8777838f2
|
7
|
+
data.tar.gz: ecab6cadfb5316739f17d8174bcb8147f0f697216cca9695709176654c891df661be1e467a869313f3f903e3c7d38714ee2192970c08a7243e86626f642e06a3
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module ShopifyApiRateLimiter
|
2
|
+
class << self
|
3
|
+
attr_accessor :logger
|
4
|
+
end
|
5
|
+
|
6
|
+
class Railties < ::Rails::Railtie
|
7
|
+
initializer 'Rails logger' do
|
8
|
+
ShopifyApiRateLimiter.logger = Rails.logger
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
if defined?(Rails)
|
13
|
+
require 'shopify_api_rate_limiter/active_resource/connection'
|
14
|
+
require 'shopify_api_rate_limiter/throttled_connection'
|
15
|
+
require 'shopify_api_rate_limiter/engine'
|
16
|
+
else
|
17
|
+
require 'shopify_api_rate_limiter/active_resource/connection'
|
18
|
+
require 'shopify_api_rate_limiter/throttled_connection'
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module ShopifyApiRateLimiter
|
2
|
+
module ThrottledConnection
|
3
|
+
SHOPIFY_SLEEP_TIME = 0.5
|
4
|
+
|
5
|
+
def request(method, path, *arguments)
|
6
|
+
if self === ShopifyAPI::Base.connection
|
7
|
+
if ShopifyAPI::Base.connection.response && ShopifyAPI.credit_maxed?
|
8
|
+
ShopifyApiRateLimiter.logger.info "Shopify rate limit credit maxed. Sleeping #{SHOPIFY_SLEEP_TIME}..."
|
9
|
+
sleep(SHOPIFY_SLEEP_TIME)
|
10
|
+
end
|
11
|
+
begin
|
12
|
+
super
|
13
|
+
rescue ActiveResource::ConnectionError => ex
|
14
|
+
if ex.response.code.to_s == '429'
|
15
|
+
ShopifyApiRateLimiter.logger.info "Shopify returned 429 (Rate Limit Exceeded). Sleeping #{SHOPIFY_SLEEP_TIME}..."
|
16
|
+
sleep(SHOPIFY_SLEEP_TIME)
|
17
|
+
retry
|
18
|
+
else
|
19
|
+
raise ex
|
20
|
+
end
|
21
|
+
end
|
22
|
+
else
|
23
|
+
super
|
24
|
+
end
|
25
|
+
rescue ShopifyAPI::Limits::LimitUnavailable => limit_unavailable
|
26
|
+
# Either Shopify API stopped sending the limit header, or we're in a stubby test
|
27
|
+
super
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path("../lib/shopify_api_rate_limiter/version", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'shopify_api_rate_limiter'
|
6
|
+
s.version = ShopifyApiRateLimiter::VERSION
|
7
|
+
s.date = '2017-01-11'
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.summary = "Rate limits API requests to the Shopify API."
|
10
|
+
s.description = "A simple (hacky) solution for rate limiting API requests to the Shopify API."
|
11
|
+
s.authors = ["Jason Buehler"]
|
12
|
+
s.email = 'jason.c.buehler@gmail.com'
|
13
|
+
s.files = `git ls-files`.split("\n")
|
14
|
+
|
15
|
+
s.homepage = 'http://rubygems.org/gems/shopify_api_rate_limiter'
|
16
|
+
s.license = 'MIT'
|
17
|
+
|
18
|
+
s.add_runtime_dependency "shopify_api", ">= 1.2.2"
|
19
|
+
s.add_development_dependency "shopify_api", ">= 1.2.2"
|
20
|
+
s.add_development_dependency "bundler", ">= 1.0.0"
|
21
|
+
s.require_path = 'lib'
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: shopify_api_rate_limiter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jason Buehler
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-01-11 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: 1.2.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.2.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: shopify_api
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.2.2
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.2.2
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.0.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.0.0
|
55
|
+
description: A simple (hacky) solution for rate limiting API requests to the Shopify
|
56
|
+
API.
|
57
|
+
email: jason.c.buehler@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- README.md
|
65
|
+
- Rakefile
|
66
|
+
- lib/shopify_api_rate_limiter.rb
|
67
|
+
- lib/shopify_api_rate_limiter/active_resource/connection.rb
|
68
|
+
- lib/shopify_api_rate_limiter/engine.rb
|
69
|
+
- lib/shopify_api_rate_limiter/throttled_connection.rb
|
70
|
+
- lib/shopify_api_rate_limiter/version.rb
|
71
|
+
- shopify_api_rate_limiter.gemspec
|
72
|
+
homepage: http://rubygems.org/gems/shopify_api_rate_limiter
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.5.1
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: Rate limits API requests to the Shopify API.
|
96
|
+
test_files: []
|