Sha256: 5e4adbdbfd690aacf13c351bb7ba948b7455dc2568652eb51d3a6ad4738e0732

Contents?: true

Size: 695 Bytes

Versions: 3

Compression:

Stored size: 695 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?
      end

      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

      private

      def redis
        Wework.redis
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
wework-0.1.4 lib/wework/token/redis_store.rb
wework-0.1.3 lib/wework/token/redis_store.rb
wework-0.1.2 lib/wework/token/redis_store.rb