Class: Wework::Token::RedisStore

Inherits:
Store
  • Object
show all
Defined in:
lib/wework/token/redis_store.rb

Instance Attribute Summary

Attributes inherited from Store

#agent

Instance Method Summary collapse

Constructor Details

#initialize(agent) ⇒ RedisStore

Returns a new instance of RedisStore.



5
6
7
8
# File 'lib/wework/token/redis_store.rb', line 5

def initialize(agent)
  raise RedisNotConfigException if redis.nil?
  super
end

Instance Method Details

#access_tokenObject



10
11
12
13
# File 'lib/wework/token/redis_store.rb', line 10

def access_token
  super
  redis.hget(key, "access_token")
end

#expired?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/wework/token/redis_store.rb', line 15

def expired?
  redis.hvals(key).empty?
end

#refresh_tokenObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/wework/token/redis_store.rb', line 19

def refresh_token
  result = super

  expires_at = Time.now.to_i + result['expires_in'].to_i - 100
  redis.hmset(
    key,
    "access_token", result['access_token'],
    "expires_at", expires_at
  )

  redis.expireat(key, expires_at)
end