Class: WeixinAuthorize::Token::Store
- Inherits:
-
Object
- Object
- WeixinAuthorize::Token::Store
- Defined in:
- lib/weixin_authorize/token/store.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
Class Method Summary collapse
Instance Method Summary collapse
- #access_token ⇒ Object
- #authenticate ⇒ Object
- #authenticate_headers ⇒ Object
- #http_get_access_token ⇒ Object
-
#initialize(client) ⇒ Store
constructor
A new instance of Store.
- #refresh_token ⇒ Object
- #set_access_token(access_token_infos = nil) ⇒ Object
- #token_expired? ⇒ Boolean
- #valid? ⇒ Boolean
Constructor Details
#initialize(client) ⇒ Store
Returns a new instance of Store.
8 9 10 |
# File 'lib/weixin_authorize/token/store.rb', line 8 def initialize(client) @client = client end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
6 7 8 |
# File 'lib/weixin_authorize/token/store.rb', line 6 def client @client end |
Class Method Details
.init_with(client) ⇒ Object
12 13 14 15 16 17 18 |
# 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 |
Instance Method Details
#access_token ⇒ Object
39 40 41 |
# File 'lib/weixin_authorize/token/store.rb', line 39 def access_token refresh_token if token_expired? end |
#authenticate ⇒ Object
24 25 26 27 28 29 30 31 32 |
# 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 ⇒ Object
57 58 59 |
# 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 ⇒ Object
53 54 55 |
# 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 ⇒ Object
34 35 36 37 |
# 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) ⇒ Object
47 48 49 50 51 |
# 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 = Time.now.to_i + token_infos["expires_in"].to_i end |
#token_expired? ⇒ Boolean
43 44 45 |
# File 'lib/weixin_authorize/token/store.rb', line 43 def token_expired? raise NotImplementedError, "Subclasses must implement a token_expired? method" end |
#valid? ⇒ Boolean
20 21 22 |
# File 'lib/weixin_authorize/token/store.rb', line 20 def valid? authenticate["valid"] end |