Sha256: 58933da66b1f2a3e602015592cbffbc132266707606fb0fd6971e80e89675acd

Contents?: true

Size: 781 Bytes

Versions: 1

Compression:

Stored size: 781 Bytes

Contents

module Wework
  module JsTicket
    class RedisStore < Store

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

      def jsapi_ticket
        super
        redis.hget(key, "ticket")
      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 - 100
          redis.hmset(
            key,
            "ticket", result.ticket,
            "expires_at", expires_at
          )

          redis.expireat(key, expires_at)
        end
      end

      private

      def redis
        Wework.redis
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wework-0.2.6 lib/wework/js_ticket/redis_store.rb