Class: SimpleWechat::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_wechat/client.rb

Defined Under Namespace

Classes: AccessToken

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#appidObject (readonly)

Returns the value of attribute appid.



14
15
16
# File 'lib/simple_wechat/client.rb', line 14

def appid
  @appid
end

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

#connectionObject



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_tokenObject



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_clientObject



25
26
27
# File 'lib/simple_wechat/client.rb', line 25

def get_auth_client
  AuthClient.new(appid, secret)
end