Sha256: c32af05154d70ec9936d41d7d8198b067525d48a98d517fd059c06d4faa1f815

Contents?: true

Size: 694 Bytes

Versions: 9

Compression:

Stored size: 694 Bytes

Contents

module Wework
  module JsTicket
    class Store

      attr_accessor :app

      def initialize(app)
        @app = app
      end

      def jsapi_ticket
        refresh_token if expired?
      end

      def expired?
        raise NotImplementedError, "Subclasses must implement a token_expired? method"
      end

      def refresh_token
        result = app.get 'get_jsapi_ticket'
        if defined?(Rails)
          Rails.logger.warn "[WEWORK] refresh JsTicket(#{app.corp_id}): #{result.inspect}"
        end

        result
      end

      private

      def key
        @key ||= Digest::MD5.hexdigest("#{JSAPI_TOKEN_PREFIX}_#{app.app_id}_#{app.app_secret}")
      end

    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
wework-0.3.4 lib/wework/js_ticket/store.rb
wework-0.3.3 lib/wework/js_ticket/store.rb
wework-0.3.2 lib/wework/js_ticket/store.rb
wework-0.3.1 lib/wework/js_ticket/store.rb
wework-0.3.0 lib/wework/js_ticket/store.rb
wework-0.2.9 lib/wework/js_ticket/store.rb
wework-0.2.8 lib/wework/js_ticket/store.rb
wework-0.2.7 lib/wework/js_ticket/store.rb
wework-0.2.6 lib/wework/js_ticket/store.rb