Class: WechatClient::Client
- Inherits:
-
Object
- Object
- WechatClient::Client
- Extended by:
- MonitorMixin
- Defined in:
- lib/wechat_client/client.rb
Constant Summary collapse
- DEFAULT =
{ app_id: nil, app_secret: nil, serial_no: nil, raise_flag: false, # 微信返回错误代码时raise verify_ssl: true, # RestClient::Request.execute 参数 auto_cache: true # 是否使用自带的缓存方式 }
- NEED_AUTO_CACHE =
[:access_token, :jsapi_ticket]
- GETTING_APIS =
WechatClient::Apis::Getting.public_instance_methods(false)
- POSTING_APIS =
WechatClient::Apis::Posting.public_instance_methods(false)
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #get(api_name, params = {}, at = nil, &block) ⇒ Object
-
#initialize(args) ⇒ Client
constructor
A new instance of Client.
- #options ⇒ Object
- #post(api_name, post_data = {}, at = nil, &block) ⇒ Object
Constructor Details
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the value of attribute error.
27 28 29 |
# File 'lib/wechat_client/client.rb', line 27 def error @error end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
27 28 29 |
# File 'lib/wechat_client/client.rb', line 27 def url @url end |
Instance Method Details
#get(api_name, params = {}, at = nil, &block) ⇒ Object
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/wechat_client/client.rb', line 61 def get(api_name, params = {}, at = nil, &block) Client.synchronize do @api.access_token = at response = request_handle(api_name, params) do |params| @url += params.to_query if params RestClient::Request.execute(method: :get, url: @url, verify_ssl: .verify_ssl) end response_handle(api_name, response, .raise_flag, &block) end end |
#options ⇒ Object
82 83 84 |
# File 'lib/wechat_client/client.rb', line 82 def OpenStruct.new(@options) end |
#post(api_name, post_data = {}, at = nil, &block) ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/wechat_client/client.rb', line 72 def post(api_name, post_data = {}, at = nil, &block) Client.synchronize do @api.access_token = at response = request_handle(api_name, post_data) do |post_data| RestClient::Request.execute(method: :post, url: @url, payload: post_data.to_json, verify_ssl: .verify_ssl) end response_handle(api_name, response, .raise_flag, &block) end end |