Class: SimpleWechat::Client
- Inherits:
-
Object
- Object
- SimpleWechat::Client
- Defined in:
- lib/simple_wechat/client.rb
Defined Under Namespace
Classes: AccessToken
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
- #connection ⇒ Object
- #get_access_token ⇒ Object
- #get_auth_client ⇒ Object
-
#initialize(appid, secret) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(appid, secret) ⇒ Client
Returns a new instance of Client.
16 17 18 |
# File 'lib/simple_wechat/client.rb', line 16 def initialize(appid, secret) @appid, @secret = appid, secret end |
Instance Attribute Details
#appid ⇒ Object (readonly)
Returns the value of attribute appid.
14 15 16 |
# File 'lib/simple_wechat/client.rb', line 14 def appid @appid end |
#secret ⇒ Object (readonly)
Returns the value of attribute secret.
14 15 16 |
# File 'lib/simple_wechat/client.rb', line 14 def secret @secret end |
Instance Method Details
#connection ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/simple_wechat/client.rb', line 29 def connection @connection ||= begin conn = Faraday.new do |faraday| faraday.adapter Faraday.default_adapter end end end |
#get_access_token ⇒ Object
20 21 22 23 |
# File 'lib/simple_wechat/client.rb', line 20 def get_access_token response = connection.get("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=#{appid}&secret=#{secret}") AccessToken.new MultiJson.load(response.body) end |
#get_auth_client ⇒ Object
25 26 27 |
# File 'lib/simple_wechat/client.rb', line 25 def get_auth_client AuthClient.new(appid, secret) end |