Class: WeixinJsSDK::AccessToken

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_inObject (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

#tokenObject (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

#fetchObject

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