tangocard 6.0.0 → 6.1.0

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: 195374af4af9dbbafb48fb692f00d4b78acd006b
4
- data.tar.gz: 1f2eaaa879ca2e69356d6027424c3e0492be19a8
3
+ metadata.gz: 4ac03de16035232e603b426c59ccd6224e782122
4
+ data.tar.gz: de61de3f8a4a361274a3a7689382b69f28972a94
5
5
  SHA512:
6
- metadata.gz: c53de8686810144fde4acc8780145afe663d7cac61cf3724d4f0f1d9e9c53df381d4ff38a2a10d774270824cd784fb12590afc4e1ce1b7c257417407b97396d9
7
- data.tar.gz: beb1ad464599fe27e5a79c40eda647e6f9d0600b7adadb447f1f23e3acc2e65be482d8b7f75af290d4a55cfe09f0f38e739be9f757bbef362bdc8e7556553ca6
6
+ metadata.gz: d736487bb1c755343ba712a77eccc2db7de51036dc5eb73f40b8a913827a811db4baba37fa3c516e1b90ecc224eb89087cb9810e3cff7e63756b1cb977d74143
7
+ data.tar.gz: 6dde06d834effdbe683bdcbcb32d52a98175388e7a0b710a743bd57bcfdb9bbc6ef374cd8e0ee28887a501da5296909006ae8b21a73618e96b5e2b945cc050dc
data/README.md CHANGED
@@ -39,11 +39,13 @@ There are three required configuration parameters:
39
39
  * `key` - The API account key you receive from Tango Card
40
40
  * `base_uri` - This defaults to the Tango Card sandbox. For production, you must specify the base URI for the production RaaS API. Make sure not to include `/raas/v1` or any trailing slashes.
41
41
 
42
- There are also three optional configuration parameters:
42
+ There are also optional configuration parameters:
43
43
 
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
49
 
48
50
  ## Getting Started
49
51
 
@@ -4,7 +4,8 @@ require 'ostruct'
4
4
 
5
5
  module Tangocard
6
6
  class Configuration
7
- attr_accessor :name, :key, :base_uri, :default_brands, :local_images, :sku_blacklist, :use_cache
7
+ attr_accessor :name, :key, :base_uri, :default_brands, :local_images, :sku_blacklist,
8
+ :use_cache, :cache_ttl
8
9
 
9
10
  def initialize
10
11
  self.name = nil
@@ -14,6 +15,7 @@ module Tangocard
14
15
  self.local_images = {}
15
16
  self.sku_blacklist = []
16
17
  self.use_cache = true
18
+ self.cache_ttl = 0
17
19
  end
18
20
  end
19
21
 
@@ -1,6 +1,8 @@
1
1
  class Tangocard::Raas
2
2
  include HTTParty
3
3
 
4
+ @@rewards_response_expires_at = 0
5
+
4
6
  # Create a new account. Returns Tangocard::Response object.
5
7
  #
6
8
  # Example:
@@ -71,7 +73,11 @@ class Tangocard::Raas
71
73
  # none
72
74
  def self.rewards_index
73
75
  if Tangocard.configuration.use_cache
76
+ clear_cache! if cache_expired?
77
+
74
78
  @@rewards_response ||= Tangocard::Response.new(get(endpoint + '/rewards', basic_auth_param))
79
+ @@rewards_response_expires_at = (Time.now.to_i + Tangocard.configuration.cache_ttl) if cache_expired?
80
+ @@rewards_response
75
81
  else
76
82
  Tangocard::Response.new(get(endpoint + '/rewards', basic_auth_param))
77
83
  end
@@ -123,6 +129,7 @@ class Tangocard::Raas
123
129
 
124
130
  def self.clear_cache!
125
131
  @@rewards_response = nil
132
+ @@rewards_response_expires_at = 0
126
133
  end
127
134
 
128
135
  private
@@ -131,6 +138,14 @@ class Tangocard::Raas
131
138
  {:basic_auth => {:username => Tangocard.configuration.name, :password => Tangocard.configuration.key}}
132
139
  end
133
140
 
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
+
134
149
  def self.endpoint
135
150
  Tangocard.configuration.base_uri + '/raas/v1.1'
136
151
  end
@@ -1,3 +1,3 @@
1
1
  module Tangocard
2
- VERSION = '6.0.0'
2
+ VERSION = '6.1.0'
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.0.0
4
+ version: 6.1.0
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-03-15 00:00:00.000000000 Z
11
+ date: 2016-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -127,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
127
  version: '0'
128
128
  requirements: []
129
129
  rubyforge_project:
130
- rubygems_version: 2.4.3
130
+ rubygems_version: 2.5.1
131
131
  signing_key:
132
132
  specification_version: 4
133
133
  summary: Ruby Wrapper for Tango Card RaaS API.