Class: Wechat::Request
- Inherits:
-
Object
- Object
- Wechat::Request
- Defined in:
- lib/wechat/request.rb
Instance Attribute Summary collapse
-
#http_verb ⇒ Object
Returns the value of attribute http_verb.
-
#params ⇒ Object
Returns the value of attribute params.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #access_token ⇒ Object
- #append_access_token ⇒ Object
-
#initialize(http_verb, path, params = {}) ⇒ Request
constructor
A new instance of Request.
- #send_request ⇒ Object
- #wechat_uri ⇒ Object
Constructor Details
#initialize(http_verb, path, params = {}) ⇒ Request
Returns a new instance of Request.
6 7 8 9 10 |
# File 'lib/wechat/request.rb', line 6 def initialize(http_verb, path, params = {}) self.path = path self.http_verb = http_verb self.params = params end |
Instance Attribute Details
#http_verb ⇒ Object
Returns the value of attribute http_verb.
4 5 6 |
# File 'lib/wechat/request.rb', line 4 def http_verb @http_verb end |
#params ⇒ Object
Returns the value of attribute params.
4 5 6 |
# File 'lib/wechat/request.rb', line 4 def params @params end |
#path ⇒ Object
Returns the value of attribute path.
4 5 6 |
# File 'lib/wechat/request.rb', line 4 def path @path end |
Instance Method Details
#access_token ⇒ Object
25 26 27 |
# File 'lib/wechat/request.rb', line 25 def access_token Wechat::AccessToken.new.token end |
#append_access_token ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/wechat/request.rb', line 38 def append_access_token if @path.include?'?' return "&access_token=#{access_token}" else return "?&access_token=#{access_token}" end end |
#send_request ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/wechat/request.rb', line 12 def send_request case http_verb.to_sym when :post RestClient.post(wechat_uri, params) do |response, request, result, &block| Wechat::Response.new(response).result end else RestClient.get(wechat_uri, :content_type => :json) do |response, request, result, &block| Wechat::Response.new(response).result end end end |
#wechat_uri ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/wechat/request.rb', line 29 def wechat_uri if (@path.include?'media/upload') || (@path.include?'media/get') base = Wechat.file_endpoint else base = Wechat.api_endpoint end [base, @path].join('/') + append_access_token end |