class WeixinAuthorize::Token::Store
Attributes
client[RW]
Public Class Methods
init_with(client)
click to toggle source
# File lib/weixin_authorize/token/store.rb, line 12 def self.init_with(client) if WeixinAuthorize.weixin_redis.nil? ObjectStore.new(client) else RedisStore.new(client) end end
new(client)
click to toggle source
# File lib/weixin_authorize/token/store.rb, line 8 def initialize(client) @client = client end
Public Instance Methods
access_token()
click to toggle source
# File lib/weixin_authorize/token/store.rb, line 39 def access_token refresh_token if token_expired? end
authenticate()
click to toggle source
# File lib/weixin_authorize/token/store.rb, line 24 def authenticate auth_result = http_get_access_token auth = false if auth_result.is_ok? set_access_token(auth_result.result) auth = true end {"valid" => auth, "handler" => auth_result} end
authenticate_headers()
click to toggle source
# File lib/weixin_authorize/token/store.rb, line 57 def authenticate_headers {grant_type: GRANT_TYPE, appid: client.app_id, secret: client.app_secret} end
http_get_access_token()
click to toggle source
# File lib/weixin_authorize/token/store.rb, line 53 def http_get_access_token WeixinAuthorize.http_get_without_token("/token", authenticate_headers) end
refresh_token()
click to toggle source
# File lib/weixin_authorize/token/store.rb, line 34 def refresh_token handle_valid_exception set_access_token end
set_access_token(access_token_infos=nil)
click to toggle source
# File lib/weixin_authorize/token/store.rb, line 47 def set_access_token(access_token_infos=nil) token_infos = access_token_infos || http_get_access_token.result client.access_token = token_infos["access_token"] client.expired_at = WeixinAuthorize.calculate_expire(token_infos["expires_in"]) end
token_expired?()
click to toggle source
# File lib/weixin_authorize/token/store.rb, line 43 def token_expired? raise NotImplementedError, "Subclasses must implement a token_expired? method" end
valid?()
click to toggle source
# File lib/weixin_authorize/token/store.rb, line 20 def valid? authenticate["valid"] end
Private Instance Methods
handle_valid_exception()
click to toggle source
# File lib/weixin_authorize/token/store.rb, line 63 def handle_valid_exception auth_result = authenticate if !auth_result["valid"] result_handler = auth_result["handler"] raise ValidAccessTokenException, result_handler.full_error_message end end