Class: Wework::Token::Base
- Inherits:
-
Object
- Object
- Wework::Token::Base
- Defined in:
- lib/wework/token/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
Constructor Details
#initialize(client) ⇒ Base
Returns a new instance of Base.
6 7 8 9 |
# File 'lib/wework/token/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/wework/token/base.rb', line 4 def client @client end |
Instance Method Details
#token ⇒ Object
11 12 13 14 |
# File 'lib/wework/token/base.rb', line 11 def token update_token if expired? redis.hget(redis_key, token_key) end |
#update_token ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/wework/token/base.rb', line 16 def update_token result = refresh_token value = result.send(token_key) if value.nil? puts "#{self.class.name} refresh token error: #{result.inspect}" else expires_at = Time.now.to_i + result.expires_in.to_i - Wework.expired_shift_seconds redis.hmset( redis_key, token_key, value, "expires_at", expires_at ) redis.expireat(redis_key, expires_at) end value end |