Class: WeChat::REST::Request
- Inherits:
-
Object
- Object
- WeChat::REST::Request
- Includes:
- Symbolizable
- Defined in:
- lib/we_chat/rest/request.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#options ⇒ Object
Returns the value of attribute options.
-
#path ⇒ Object
Returns the value of attribute path.
-
#request_method ⇒ Object
(also: #verb)
Returns the value of attribute request_method.
-
#uri ⇒ Object
Returns the value of attribute uri.
Instance Method Summary collapse
-
#initialize(_client, request_method, path, options = {}) ⇒ Request
constructor
A new instance of Request.
- #perform ⇒ Array, Hash
Constructor Details
#initialize(_client, request_method, path, options = {}) ⇒ Request
Returns a new instance of Request.
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/we_chat/rest/request.rb', line 17 def initialize(_client, request_method, path, = {}) @client = _client request_params = .delete(:params) unless [:params].nil? request_params ||= {} request_params[:access_token] = @client.access_token if @client.access_token? template = ::Addressable::Template.new(path.start_with?('http') ? path : WeChat.wechat_api_base_url + path + "{?query*}") @uri = template.({ "query" => request_params }) (request_method, ) @path = uri.path @options = end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
13 14 15 |
# File 'lib/we_chat/rest/request.rb', line 13 def client @client end |
#headers ⇒ Object
Returns the value of attribute headers.
13 14 15 |
# File 'lib/we_chat/rest/request.rb', line 13 def headers @headers end |
#options ⇒ Object
Returns the value of attribute options.
13 14 15 |
# File 'lib/we_chat/rest/request.rb', line 13 def @options end |
#path ⇒ Object
Returns the value of attribute path.
13 14 15 |
# File 'lib/we_chat/rest/request.rb', line 13 def path @path end |
#request_method ⇒ Object Also known as: verb
Returns the value of attribute request_method.
13 14 15 |
# File 'lib/we_chat/rest/request.rb', line 13 def request_method @request_method end |
#uri ⇒ Object
Returns the value of attribute uri.
13 14 15 |
# File 'lib/we_chat/rest/request.rb', line 13 def uri @uri end |
Instance Method Details
#perform ⇒ Array, Hash
32 33 34 35 36 |
# File 'lib/we_chat/rest/request.rb', line 32 def perform = @request_method == :get ? :params : @request_method == :post ? :json : :form response = HTTP.with(@headers).public_send(@request_method, @uri.to_s, => @options) fail_or_return_response_body(response) end |