Class: WeixinJsSDK::AccessToken
- Inherits:
-
Object
- Object
- WeixinJsSDK::AccessToken
- Defined in:
- lib/weixin_js_sdk/access_token.rb
Constant Summary collapse
- URI_TEMPLATE =
'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%{app_id}&secret=%{app_secret}'.freeze
Instance Attribute Summary collapse
-
#expires_in ⇒ Object
readonly
Returns the value of attribute expires_in.
-
#token ⇒ Object
(also: #access_token)
readonly
Returns the value of attribute token.
Instance Method Summary collapse
-
#fetch ⇒ Object
DEPRECATED: Please use
tokeninstead. -
#initialize(app_id: '', app_secret: '') ⇒ AccessToken
constructor
A new instance of AccessToken.
Constructor Details
#initialize(app_id: '', app_secret: '') ⇒ AccessToken
Returns a new instance of AccessToken.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/weixin_js_sdk/access_token.rb', line 7 def initialize(app_id: '', app_secret: '') url = URI_TEMPLATE % { app_id: app_id, app_secret: app_secret } json = Util.get_json(url) @token = json['access_token'] @expires_in = json['expires_in'] end |
Instance Attribute Details
#expires_in ⇒ Object (readonly)
Returns the value of attribute expires_in.
5 6 7 |
# File 'lib/weixin_js_sdk/access_token.rb', line 5 def expires_in @expires_in end |
#token ⇒ Object (readonly) Also known as: access_token
Returns the value of attribute token.
5 6 7 |
# File 'lib/weixin_js_sdk/access_token.rb', line 5 def token @token end |
Instance Method Details
#fetch ⇒ Object
DEPRECATED: Please use token instead.
20 21 22 23 |
# File 'lib/weixin_js_sdk/access_token.rb', line 20 def fetch warn "[DEPRECATION] `fetch` is deprecated. Please use `token` instead." token end |