Sha256: a12ae6be17461fbeadcc4c6e72d90f87e8f8c6c88cef2cdf63313b5b39d0089b

Contents?: true

Size: 741 Bytes

Versions: 8

Compression:

Stored size: 741 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
        if result.success?
          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
      end

      private

      def redis
        Wework.redis
      end

    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
wework-0.2.4 lib/wework/token/redis_store.rb
wework-0.2.3 lib/wework/token/redis_store.rb
wework-0.2.2 lib/wework/token/redis_store.rb
wework-0.2.0 lib/wework/token/redis_store.rb
wework-0.1.9 lib/wework/token/redis_store.rb
wework-0.1.8 lib/wework/token/redis_store.rb
wework-0.1.7 lib/wework/token/redis_store.rb
wework-0.1.6 lib/wework/token/redis_store.rb