Class: Wework::JsTicket::RedisStore

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

Instance Attribute Summary

Attributes inherited from Store

#app

Instance Method Summary collapse

Constructor Details

#initialize(agent) ⇒ RedisStore

Returns a new instance of RedisStore.



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

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

Instance Method Details

#expired?Boolean

Returns:

  • (Boolean)


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

def expired?
  redis.hvals(key).empty? || redis.hget(key, "expires_at").to_i <= Time.now.to_i
end

#jsapi_ticketObject



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

def jsapi_ticket
  super
  redis.hget(key, "ticket")
end

#refresh_tokenObject



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

def refresh_token
  result = super
  if result.success?
    expires_at = Time.now.to_i + result.expires_in.to_i - Wework.expired_shift_seconds
    redis.hmset(
      key,
      "ticket", result.ticket,
      "expires_at", expires_at
    )

    redis.expireat(key, expires_at)
  end
end