Class: WeixinAuthorize::Storage
- Inherits:
-
Object
- Object
- WeixinAuthorize::Storage
show all
- Defined in:
- lib/weixin_authorize/adapter/storage.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(client) ⇒ Storage
Returns a new instance of Storage.
8
9
10
|
# File 'lib/weixin_authorize/adapter/storage.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/adapter/storage.rb', line 6
def client
@client
end
|
Class Method Details
.init_with(client) ⇒ Object
Instance Method Details
#access_token ⇒ Object
38
39
40
|
# File 'lib/weixin_authorize/adapter/storage.rb', line 38
def access_token
authenticate if token_expired?
end
|
#authenticate ⇒ Object
33
34
35
36
|
# File 'lib/weixin_authorize/adapter/storage.rb', line 33
def authenticate
raise "APPID or APPSECRET is invalid" if !valid?
set_access_token_for_client
end
|
52
53
54
|
# File 'lib/weixin_authorize/adapter/storage.rb', line 52
def
{grant_type: "client_credential", appid: client.app_id, secret: client.app_secret}
end
|
#http_get_access_token ⇒ Object
#set_access_token_for_client(access_token_infos = nil) ⇒ Object
42
43
44
45
46
|
# File 'lib/weixin_authorize/adapter/storage.rb', line 42
def set_access_token_for_client(access_token_infos=nil)
token_infos = access_token_infos || http_get_access_token
client.access_token = token_infos["access_token"]
client.expired_at = Time.now.to_i + token_infos["expires_in"].to_i
end
|
#token_expired? ⇒ Boolean
29
30
31
|
# File 'lib/weixin_authorize/adapter/storage.rb', line 29
def token_expired?
raise NotImplementedError, "Subclasses must implement a token_expired? method"
end
|
#valid? ⇒ Boolean
20
21
22
23
24
25
26
27
|
# File 'lib/weixin_authorize/adapter/storage.rb', line 20
def valid?
valid_result = http_get_access_token
if valid_result.keys.include?("access_token")
set_access_token_for_client(valid_result)
return true
end
false
end
|