shopify_unlimited 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module ShopifyUnlimited
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
@@ -17,16 +17,29 @@ module ShopifyUnlimited
17
17
  end
18
18
 
19
19
  def cached_time(max)
20
- time = Time.now
21
- time = memcached.cas(cache_key, 500) do |cached_time|
22
- return time if cached_time.nil?
23
- ((time - cached_time) > max) ? time : cached_time
20
+ now = Time.now
21
+ result = now
22
+ unless memcached.add(cache_key, now, 500)
23
+ memcached.cas(cache_key, 500) do |cached_time|
24
+ result = ((now - cached_time) > max) ? now : cached_time
25
+ result
26
+ end
24
27
  end
25
- time
28
+ result
26
29
  end
27
30
 
28
31
  def set_cached_time(time)
32
+
29
33
  memcached.set(cache_key, time, 500)
34
+ end
35
+
36
+
37
+ def estimated_time_until_reset
38
+ credit_record = ShopifyAPI::Base.connection.shopify_credit
39
+ time = credit_record.time unless credit_record.nil?
40
+ time ||= cached_time(ShopifyUnlimited::SHOPIFY_CREDIT_LIMIT_PERIOD)
41
+ est = ShopifyUnlimited::SHOPIFY_CREDIT_LIMIT_PERIOD - (Time.now - time)
42
+ [est, 0].max
30
43
  end
31
44
  end
32
45
  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.9
4
+ version: 0.0.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -141,7 +141,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
141
141
  version: '0'
142
142
  segments:
143
143
  - 0
144
- hash: -2004155460497678589
144
+ hash: -1618288233735018532
145
145
  required_rubygems_version: !ruby/object:Gem::Requirement
146
146
  none: false
147
147
  requirements:
@@ -150,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
150
  version: '0'
151
151
  segments:
152
152
  - 0
153
- hash: -2004155460497678589
153
+ hash: -1618288233735018532
154
154
  requirements: []
155
155
  rubyforge_project:
156
156
  rubygems_version: 1.8.25