Class: Baiwang::TokenStore::Base
- Inherits:
-
Object
- Object
- Baiwang::TokenStore::Base
- Defined in:
- lib/baiwang/token_store/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
Instance Method Summary collapse
-
#initialize(client) ⇒ Base
constructor
A new instance of Base.
- #token ⇒ Object
- #update_token ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(client) ⇒ Base
Returns a new instance of Base.
6 7 8 9 |
# File 'lib/baiwang/token_store/base.rb', line 6 def initialize(client) @client = client raise RedisNotConfigException if redis.nil? end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
4 5 6 |
# File 'lib/baiwang/token_store/base.rb', line 4 def client @client end |
Instance Method Details
#token ⇒ Object
11 12 13 14 |
# File 'lib/baiwang/token_store/base.rb', line 11 def token update_token if expired? redis.hget(redis_key, token_key) end |
#update_token ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/baiwang/token_store/base.rb', line 20 def update_token data = fetch_token.data value = data[token_key] if value.nil? Baiwang.logger.error "#{self.class.name} fetch token error: #{data.inspect}" else expires_at = Time.now.to_i + data['expires_in'].to_i - 120 redis.hmset( redis_key, token_key, value, 'expires_at', expires_at ) redis.expireat(redis_key, expires_at) end value end |
#valid? ⇒ Boolean
16 17 18 |
# File 'lib/baiwang/token_store/base.rb', line 16 def valid? token.present? end |