Class: Kount::Adapters::RedisAdapter
- Inherits:
-
Object
- Object
- Kount::Adapters::RedisAdapter
- Defined in:
- lib/kount/adapters/redis_adapter.rb
Instance Method Summary collapse
- #get_token(api_key:, client:) ⇒ Object
-
#initialize(redis_client = nil) ⇒ RedisAdapter
constructor
A new instance of RedisAdapter.
- #store_token(api_key:, client:, token:, expires_in:) ⇒ Object
Constructor Details
#initialize(redis_client = nil) ⇒ RedisAdapter
6 7 8 |
# File 'lib/kount/adapters/redis_adapter.rb', line 6 def initialize(redis_client = nil) @redis = redis_client end |
Instance Method Details
#get_token(api_key:, client:) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/kount/adapters/redis_adapter.rb', line 10 def get_token(api_key:, client:) key = token_key(api_key, client) json = @redis.get(key) return nil unless json JSON.parse(json, symbolize_names: true) end |
#store_token(api_key:, client:, token:, expires_in:) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/kount/adapters/redis_adapter.rb', line 18 def store_token(api_key:, client:, token:, expires_in:) key = token_key(api_key, client) expiry = Time.now.to_i + expires_in data = { token: token, expiry: expiry } @redis.set(key, data.to_json, ex: expires_in) end |