Class: Lark::TokenStore::Base
- Inherits:
-
Object
- Object
- Lark::TokenStore::Base
show all
- Defined in:
- lib/lark/token_store/base.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(client) ⇒ Base
Returns a new instance of Base.
6
7
8
9
|
# File 'lib/lark/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/lark/token_store/base.rb', line 4
def client
@client
end
|
Instance Method Details
#token ⇒ Object
11
12
13
14
|
# File 'lib/lark/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/lark/token_store/base.rb', line 20
def update_token
data = fetch_token.data
value = data[token_key]
if value.nil?
Lark.logger.error "#{self.class.name} fetch token error: #{data.inspect}"
else
expires_at = Time.now.to_i + data['expire'].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/lark/token_store/base.rb', line 16
def valid?
token.present?
end
|