tangocard 6.2.0 → 7.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7f7d4ed6be48184c160a1fdba063b0a4927dce67
4
- data.tar.gz: eab7f8d2e7558c42e1fc45f5a110eb2f52fe6457
3
+ metadata.gz: 4460feb6c9829bf987ebcee0a5f3bd0b0f045eda
4
+ data.tar.gz: 2e06c8a3d60c2ffd149b6e0312f5ea0934da3ec9
5
5
  SHA512:
6
- metadata.gz: 232120b85c5a52108958f0534abda04c4069cb07c7d489a7cfb227eb81071207b0767528c481c1da34b7a265fe081daf7aa265ec67faf36c3119926254c2bfec
7
- data.tar.gz: 1a7d9eecaf0a0ca4b0d39a08169061c31f5dc7ebe42accd322f66cc7e25dff1dcbe3498df486eff127bce04ce7aa1a0d44d872c6023f72981884b13c9b8e28da
6
+ metadata.gz: 647a675699b4fec0423e3d174c28cc532994c2a924c252bab09e33455fb42d7a7b7013d02929cf7b9569a3fd8bcf2b5632c0aafcbe55d44b9e02b94b67e3c846
7
+ data.tar.gz: a9a36089994b9fec78ba489315da6534fd14a32d85cdc8676fd6226a011559f5275acebc64ac5902da20fbd5522522f6c16e3522740aa5931e5daee0305800df
data/README.md CHANGED
@@ -44,8 +44,9 @@ There are also optional configuration parameters:
44
44
  * `default_brands` - An array of strings for the brands you want to retrieve with `Tangocard::Brand.default`. The strings should match the unique brand `description` fields exactly.
45
45
  * `local_images` - An array of local image names/URIs that you want to display instead of the default Tango Card-provided `image_url`. `image_url` is sometimes blank, so this can be handy in those cases.
46
46
  * `sku_blacklist` - Reward SKUs that are blacklisted, ie. should never be returned as a purchasable reward.
47
- * `use_cache` - Use cache for Tangocard::Brand queries, defaults to `true`.
48
- * `cache_ttl` - Cache time-to-Live in seconds, only effective if `use_cache` is enabled. Default is `0` (cache never expires).
47
+ * `use_cache` - Use cache for Tangocard::Brand queries, defaults to `true`. The cache can be refreshed by calling `Tangocard.warm_cache`
48
+ * `cache` - Which cache to use, defaults to `ActiveSupport::Cache::MemoryStore`. Using an out-of-process cache e.g. hosted memcache will improve performance and stability.
49
+ * `logger` - i.e. `Rails.logger`
49
50
 
50
51
  ## Getting Started
51
52
 
data/lib/tangocard.rb CHANGED
@@ -1,11 +1,17 @@
1
1
  require 'httparty'
2
2
  require 'money'
3
3
  require 'ostruct'
4
+ require 'active_support'
5
+ require 'active_support/cache/memory_store'
6
+ require 'tangocard/version'
4
7
 
5
8
  module Tangocard
9
+
10
+ CACHE_PREFIX = "tangocard:#{VERSION}:"
11
+
6
12
  class Configuration
7
13
  attr_accessor :name, :key, :base_uri, :default_brands, :local_images, :sku_blacklist,
8
- :use_cache, :cache_ttl
14
+ :use_cache, :cache, :logger
9
15
 
10
16
  def initialize
11
17
  self.name = nil
@@ -15,7 +21,8 @@ module Tangocard
15
21
  self.local_images = {}
16
22
  self.sku_blacklist = []
17
23
  self.use_cache = true
18
- self.cache_ttl = 0
24
+ self.cache = ActiveSupport::Cache::MemoryStore.new
25
+ self.logger = Logger.new(STDOUT)
19
26
  end
20
27
  end
21
28
 
@@ -25,6 +32,12 @@ module Tangocard
25
32
 
26
33
  def self.configure
27
34
  yield(configuration) if block_given?
35
+ warm_cache if configuration.use_cache
36
+ end
37
+
38
+ def self.warm_cache
39
+ configuration.cache.write("#{Tangocard::CACHE_PREFIX}rewards_index", Tangocard::Raas.rewards_index(use_cache: false))
40
+ configuration.logger.info('Warmed Tangocard cache')
28
41
  end
29
42
  end
30
43
 
@@ -43,4 +56,3 @@ require 'tangocard/order_not_found_exception'
43
56
  require 'tangocard/raas_exception'
44
57
  require 'tangocard/reward'
45
58
  require 'tangocard/exchange_rate'
46
-
@@ -1,18 +1,6 @@
1
1
  class Tangocard::Brand
2
2
  attr_reader :description, :rewards
3
3
 
4
- # Clear all cached responses. Next request for brand info will pull fresh from the Tango Card API.
5
- #
6
- # Example:
7
- # >> Tangocard::Brand.clear_cache!
8
- # => true
9
- #
10
- # Arguments:
11
- # none
12
- def self.clear_cache!
13
- Tangocard::Raas.clear_cache!
14
- end
15
-
16
4
  # Return an array of all brands.
17
5
  #
18
6
  # Example:
@@ -1,18 +1,6 @@
1
1
  class Tangocard::ExchangeRate
2
2
  attr_reader :currency_code, :rate
3
3
 
4
- # Clear all cached responses. Next request for exchange rate info will pull fresh from the Tango Card API.
5
- #
6
- # Example:
7
- # >> Tangocard::ExchangeRate.clear_cache!
8
- # => true
9
- #
10
- # Arguments:
11
- # none
12
- def self.clear_cache!
13
- Tangocard::Raas.clear_cache!
14
- end
15
-
16
4
  # Return current currency exchange rate timestamp.
17
5
  #
18
6
  # Example:
@@ -1,8 +1,6 @@
1
1
  class Tangocard::Raas
2
2
  include HTTParty
3
3
 
4
- @@rewards_response_expires_at = 0
5
-
6
4
  # Create a new account. Returns Tangocard::Response object.
7
5
  #
8
6
  # Example:
@@ -71,13 +69,9 @@ class Tangocard::Raas
71
69
  #
72
70
  # Arguments:
73
71
  # none
74
- def self.rewards_index
75
- if Tangocard.configuration.use_cache
76
- clear_cache! if cache_expired?
77
-
78
- @@rewards_response ||= Tangocard::Response.new(get_request('/rewards'))
79
- @@rewards_response_expires_at = (Time.now.to_i + Tangocard.configuration.cache_ttl) if cache_expired?
80
- @@rewards_response
72
+ def self.rewards_index(use_cache: true)
73
+ if Tangocard.configuration.use_cache && use_cache
74
+ Tangocard.configuration.cache.read("#{Tangocard::CACHE_PREFIX}rewards_index")
81
75
  else
82
76
  Tangocard::Response.new(get_request('/rewards'))
83
77
  end
@@ -127,25 +121,12 @@ class Tangocard::Raas
127
121
  Tangocard::Response.new(get_request("/orders#{query_string}"))
128
122
  end
129
123
 
130
- def self.clear_cache!
131
- @@rewards_response = nil
132
- @@rewards_response_expires_at = 0
133
- end
134
-
135
124
  private
136
125
 
137
126
  def self.basic_auth_param
138
127
  { basic_auth: { username: Tangocard.configuration.name, password: Tangocard.configuration.key } }
139
128
  end
140
129
 
141
- def self.use_cache_ttl?
142
- Tangocard.configuration.use_cache && Tangocard.configuration.cache_ttl > 0
143
- end
144
-
145
- def self.cache_expired?
146
- use_cache_ttl? && @@rewards_response_expires_at < Time.now.to_i
147
- end
148
-
149
130
  def self.endpoint
150
131
  "#{Tangocard.configuration.base_uri}/raas/v1.1"
151
132
  end
@@ -1,3 +1,3 @@
1
1
  module Tangocard
2
- VERSION = '6.2.0'
2
+ VERSION = '7.0.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tangocard
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.2.0
4
+ version: 7.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Raphael Crawford-Marks
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-01 00:00:00.000000000 Z
11
+ date: 2016-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -52,20 +52,34 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '4.2'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '4.2'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rspec
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
- - - ">="
73
+ - - "~>"
60
74
  - !ruby/object:Gem::Version
61
- version: '0'
75
+ version: '3.5'
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
- - - ">="
80
+ - - "~>"
67
81
  - !ruby/object:Gem::Version
68
- version: '0'
82
+ version: '3.5'
69
83
  description: |-
70
84
  Tango Card provides a RaaS API for developers (https://www.tangocard.com/docs/raas-api/). This gem
71
85
  provides commonsense Ruby objects to wrap the JSON endpoints of the RaaS API.
@@ -96,7 +110,8 @@ files:
96
110
  - lib/tangocard/reward.rb
97
111
  - lib/tangocard/version.rb
98
112
  homepage: http://bonus.ly
99
- licenses: []
113
+ licenses:
114
+ - MIT
100
115
  metadata: {}
101
116
  post_install_message:
102
117
  rdoc_options: []