Class: Wechat::AccessToken
- Inherits:
-
Object
- Object
- Wechat::AccessToken
- Defined in:
- lib/wechat/access_token.rb
Instance Attribute Summary collapse
-
#appid ⇒ Object
Returns the value of attribute appid.
-
#secret ⇒ Object
Returns the value of attribute secret.
Instance Method Summary collapse
-
#initialize ⇒ AccessToken
constructor
A new instance of AccessToken.
- #refresh ⇒ Object
- #token ⇒ Object
Constructor Details
#initialize ⇒ AccessToken
Returns a new instance of AccessToken.
5 6 7 8 9 10 11 12 |
# File 'lib/wechat/access_token.rb', line 5 def initialize raise 'Wechat.api_appid not set' if Wechat.api_appid.nil? raise 'Wechat.api_appsecret not set' if Wechat.api_appsecret.nil? @appid = Wechat.api_appid @secret = Wechat.api_appsecret end |
Instance Attribute Details
#appid ⇒ Object
Returns the value of attribute appid.
3 4 5 |
# File 'lib/wechat/access_token.rb', line 3 def appid @appid end |
#secret ⇒ Object
Returns the value of attribute secret.
3 4 5 |
# File 'lib/wechat/access_token.rb', line 3 def secret @secret end |
Instance Method Details
#refresh ⇒ Object
18 19 20 21 22 |
# File 'lib/wechat/access_token.rb', line 18 def refresh url = "#{Wechat.api_endpoint}/token" data = RestClient.get(url, params:{grant_type: "client_credential", appid: @appid, secret: @secret}) return valid_token(data) end |
#token ⇒ Object
14 15 16 |
# File 'lib/wechat/access_token.rb', line 14 def token Wechat.access_token ||= self.refresh end |