Class: Wechat::AuthClient
- Inherits:
-
Object
- Object
- Wechat::AuthClient
- Defined in:
- lib/wechat/auth_client.rb,
lib/wechat/auth_client/version.rb
Defined Under Namespace
Classes: AccessToken
Constant Summary collapse
- VERSION =
"1.0.0"
Instance Attribute Summary collapse
-
#appid ⇒ Object
readonly
Returns the value of attribute appid.
-
#secret ⇒ Object
readonly
Returns the value of attribute secret.
Instance Method Summary collapse
- #authorize_url(redirect_uri, state, options = {}) ⇒ Object
- #connection ⇒ Object
- #get_token(code) ⇒ Object
-
#initialize(appid, secret) ⇒ AuthClient
constructor
A new instance of AuthClient.
Constructor Details
#initialize(appid, secret) ⇒ AuthClient
Returns a new instance of AuthClient.
19 20 21 |
# File 'lib/wechat/auth_client.rb', line 19 def initialize(appid, secret) @appid, @secret = appid, secret end |
Instance Attribute Details
#appid ⇒ Object (readonly)
Returns the value of attribute appid.
17 18 19 |
# File 'lib/wechat/auth_client.rb', line 17 def appid @appid end |
#secret ⇒ Object (readonly)
Returns the value of attribute secret.
17 18 19 |
# File 'lib/wechat/auth_client.rb', line 17 def secret @secret end |
Instance Method Details
#authorize_url(redirect_uri, state, options = {}) ⇒ Object
23 24 25 26 |
# File 'lib/wechat/auth_client.rb', line 23 def (redirect_uri, state, = {}) scope = [:scope] ||= "snsapi_base" "https://open.weixin.qq.com/connect/oauth2/authorize?appid=#{appid}&redirect_uri=#{CGI.escape redirect_uri}&response_type=code&scope=#{scope}&state=#{state}#wechat_redirect" end |
#connection ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/wechat/auth_client.rb', line 33 def connection @connection ||= begin conn = Faraday.new do |faraday| faraday.adapter Faraday.default_adapter end end end |
#get_token(code) ⇒ Object
28 29 30 31 |
# File 'lib/wechat/auth_client.rb', line 28 def get_token(code) response = connection.get("https://api.weixin.qq.com/sns/oauth2/access_token?appid=#{appid}&secret=#{secret}&code=#{code}&grant_type=authorization_code") access_token = AccessToken.new MultiJson.load(response.body) end |