shopify_unlimited 0.0.5 → 0.0.6
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.
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# ShopifyUnlimited
|
2
2
|
|
3
|
-
|
3
|
+
1. Allows API calls like products = Product.find(:all, params:{limit: false}), which will make as many requests as needed to fetch all Products in batches of 250. The result set can be queried for the number of requests required: ```products.requests_made```
|
4
|
+
2.
|
5
|
+
2. Attempts to record api limits a little better by adding ```ShopifyAPI::Base.connection.shopify_credit```. This object contains the credit used since the first request (in a given process) and the time of the first request. It resets when the credit used goes down or the time elapsed has been more than 5 minutes.
|
4
6
|
|
5
7
|
## Installation
|
6
8
|
|
@@ -16,10 +18,6 @@ Or install it yourself as:
|
|
16
18
|
|
17
19
|
$ gem install shopify_unlimited
|
18
20
|
|
19
|
-
## Usage
|
20
|
-
|
21
|
-
TODO: Write usage instructions here
|
22
|
-
|
23
21
|
## Contributing
|
24
22
|
|
25
23
|
1. Fork it
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module ::ShopifyUnlimited
|
2
|
+
class CreditUsed
|
3
|
+
SHOPIFY_CREDIT_LIMIT_PERIOD = 5.minutes
|
4
|
+
|
5
|
+
attr_accessor :time, :used
|
6
|
+
def initialize(used)
|
7
|
+
@time = Time.now
|
8
|
+
@used = used
|
9
|
+
end
|
10
|
+
|
11
|
+
def stale?(used)
|
12
|
+
(@used > used) || ((Time.now - @time) > SHOPIFY_CREDIT_LIMIT_PERIOD)
|
13
|
+
end
|
14
|
+
|
15
|
+
def estimated_time_until_reset
|
16
|
+
est = SHOPIFY_CREDIT_LIMIT_PERIOD - (Time.now - @time)
|
17
|
+
[est, 0].max
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
module ::ActiveResource
|
24
|
+
class Connection
|
25
|
+
SHOPIFY_CREDIT_LIMIT_HEADER_PARAM = 'http_x_shopify_shop_api_call_limit'
|
26
|
+
|
27
|
+
attr_reader :shopify_credit
|
28
|
+
def handle_response_with_response_time_capture(response)
|
29
|
+
handle_response_without_response_time_capture(response)
|
30
|
+
if(shopify_credit_header = response[SHOPIFY_CREDIT_LIMIT_HEADER_PARAM])
|
31
|
+
used = shopify_credit_header.split('/').shift.to_i
|
32
|
+
|
33
|
+
if @shopify_credit.nil? || @shopify_credit.stale?(used)
|
34
|
+
@shopify_credit = ::ShopifyUnlimited::CreditUsed.new(used)
|
35
|
+
else
|
36
|
+
@shopify_credit.used = used
|
37
|
+
end
|
38
|
+
end
|
39
|
+
response
|
40
|
+
end
|
41
|
+
alias_method_chain :handle_response, :response_time_capture
|
42
|
+
end
|
43
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shopify_unlimited
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-07-
|
12
|
+
date: 2013-07-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activeresource
|
@@ -122,6 +122,7 @@ files:
|
|
122
122
|
- Rakefile
|
123
123
|
- lib/shopify_unlimited.rb
|
124
124
|
- lib/shopify_unlimited/active_resource/base_extensions.rb
|
125
|
+
- lib/shopify_unlimited/active_resource/connection_extensions.rb
|
125
126
|
- lib/shopify_unlimited/version.rb
|
126
127
|
- shopify_unlimited.gemspec
|
127
128
|
- spec/spec_helper.rb
|
@@ -140,7 +141,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
140
141
|
version: '0'
|
141
142
|
segments:
|
142
143
|
- 0
|
143
|
-
hash:
|
144
|
+
hash: -4386607660778254027
|
144
145
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
146
|
none: false
|
146
147
|
requirements:
|
@@ -149,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
150
|
version: '0'
|
150
151
|
segments:
|
151
152
|
- 0
|
152
|
-
hash:
|
153
|
+
hash: -4386607660778254027
|
153
154
|
requirements: []
|
154
155
|
rubyforge_project:
|
155
156
|
rubygems_version: 1.8.25
|