Sha256: 4be8e8e1d02c674806c9904c100fe7c3260b94113255b8109f4ed900142a7e8f

Contents?: true

Size: 821 Bytes

Versions: 5

Compression:

Stored size: 821 Bytes

Contents

module Wework
  module Token
    class RedisStore < Store

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

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

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

      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,
            "access_token", result.access_token,
            "expires_at", expires_at
          )

          redis.expireat(key, expires_at)
        end
      end

      private

      def redis
        Wework.redis
      end

    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
wework-0.3.1 lib/wework/token/redis_store.rb
wework-0.3.0 lib/wework/token/redis_store.rb
wework-0.2.9 lib/wework/token/redis_store.rb
wework-0.2.8 lib/wework/token/redis_store.rb
wework-0.2.7 lib/wework/token/redis_store.rb