class MpWeixin::Interface::Base
The Base
class of API
Public Class Methods
new(client)
click to toggle source
# File lib/mp_weixin/interface/base.rb, line 6 def initialize(client) @client = client end
Public Instance Methods
default_request_params()
click to toggle source
# File lib/mp_weixin/interface/base.rb, line 10 def default_request_params access_token = @client.token.token #request_params = {"oauth_consumer_key" => self.id, "access_token" => access_token, "openid" => params["openid"], "oauth_version" => "2.a", "scope" => "all"} # {"appid" => @client.id, "access_token" => access_token} {"access_token" => access_token} end
get(path, opts={}, &block)
click to toggle source
# File lib/mp_weixin/interface/base.rb, line 33 def get(path, opts={}, &block) request(:get, path, opts, &block) end
post(path, opts={}, &block)
click to toggle source
# 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)
click to toggle source
# 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[:params].merge!(default_request_params) opts = ActiveSupport::HashWithIndifferentAccess.new(opts) response = @client.token.request(verb, path, opts, &block) if response.error raise Error.new(response) end response end