shopify_unlimited 0.0.7 → 0.0.8

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.
@@ -1,3 +1,30 @@
1
1
  require "shopify_unlimited/version"
2
2
  require 'shopify_unlimited/active_resource/base_extensions'
3
3
  require 'shopify_unlimited/active_resource/connection_extensions'
4
+
5
+ module ShopifyUnlimited
6
+ class << self
7
+ attr_accessor :use_memcached
8
+ def memcached
9
+ return nil unless use_memcached
10
+ @memcached ||= Dalli::Client.new()
11
+ end
12
+
13
+ def cache_key
14
+ URI.parse(ShopifyAPI::Base.site.to_s).host + "_api_reset_time"
15
+ end
16
+
17
+ def cached_time(max)
18
+ time = Time.now
19
+ time = memcached.cas(cache_key, 500) do |cached_time|
20
+ return time if cached_time.nil?
21
+ ((time - cached_time) > max) ? time : cached_time
22
+ end
23
+ time
24
+ end
25
+
26
+ def set_cached_time(time)
27
+ memcached.set(cache_key, time, 500)
28
+ end
29
+ end
30
+ end
@@ -27,11 +27,17 @@ module ::ActiveResource
27
27
  attr_reader :shopify_credit
28
28
  def handle_response_with_response_time_capture(response)
29
29
  handle_response_without_response_time_capture(response)
30
+
30
31
  if(shopify_credit_header = response[SHOPIFY_CREDIT_LIMIT_HEADER_PARAM])
31
32
  used = shopify_credit_header.split('/').shift.to_i
32
33
 
33
- if @shopify_credit.nil? || @shopify_credit.stale?(used)
34
+ if @shopify_credit.nil?
35
+ cached_time = ::ShopifyUnlimited.cached_time(SHOPIFY_CREDIT_LIMIT_PERIOD)
34
36
  @shopify_credit = ::ShopifyUnlimited::CreditUsed.new(used)
37
+ @shopify_credit.time = cached_time
38
+ elsif @shopify_credit.stale?(used)
39
+ @shopify_credit = ::ShopifyUnlimited::CreditUsed.new(used)
40
+ ::ShopifyUnlimited.set_cached_time(Time.now)
35
41
  else
36
42
  @shopify_credit.used = used
37
43
  end
@@ -1,3 +1,3 @@
1
1
  module ShopifyUnlimited
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  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.7
4
+ version: 0.0.8
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-26 00:00:00.000000000 Z
12
+ date: 2013-07-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activeresource
@@ -141,7 +141,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
141
141
  version: '0'
142
142
  segments:
143
143
  - 0
144
- hash: -4376564070469054794
144
+ hash: -3723036348275054820
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: -4376564070469054794
153
+ hash: -3723036348275054820
154
154
  requirements: []
155
155
  rubyforge_project:
156
156
  rubygems_version: 1.8.25