Class: MpWeixin::Interface::Base
- Inherits:
-
Object
- Object
- MpWeixin::Interface::Base
show all
- Defined in:
- lib/mp_weixin/interface/base.rb
Overview
Instance Method Summary
collapse
Constructor Details
#initialize(client) ⇒ Base
Returns a new instance of Base.
6
7
8
|
# File 'lib/mp_weixin/interface/base.rb', line 6
def initialize(client)
@client = client
end
|
Instance Method Details
#default_request_params ⇒ Object
10
11
12
13
14
15
|
# File 'lib/mp_weixin/interface/base.rb', line 10
def default_request_params
access_token = @client.token.token
{"access_token" => access_token}
end
|
#get(path, opts = {}, &block) ⇒ Object
33
34
35
|
# File 'lib/mp_weixin/interface/base.rb', line 33
def get(path, opts={}, &block)
request(:get, path, opts, &block)
end
|
#post(path, opts = {}, &block) ⇒ Object
37
38
39
|
# File 'lib/mp_weixin/interface/base.rb', line 37
def post(path, opts={}, &block)
request(:post, path, opts, &block)
end
|
#request(verb, path, opts = {}, &block) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/mp_weixin/interface/base.rb', line 17
def request(verb, path, opts={}, &block)
unless @client.is_authorized?
raise "I can't find a valid access_token. Forgot to get it or expired?"
end
opts[:params] ||= {}
opts = ActiveSupport::HashWithIndifferentAccess.new(opts)
response = @client.token.request(verb, path, opts, &block)
if response.error
raise Error.new(response)
end
response
end
|