Class: TimeTree::HttpCommand
- Inherits:
-
Object
- Object
- TimeTree::HttpCommand
- Defined in:
- lib/timetree/http_command.rb
Overview
Command for HTTP request.
Instance Method Summary collapse
- #delete(path, params = {}) ⇒ Object
- #get(path, params = {}) ⇒ Object
-
#initialize(host, client) ⇒ HttpCommand
constructor
A new instance of HttpCommand.
-
#post(path, body_params = {}, &block) ⇒ Object
The request bodythat will eventually be converted to JSON.
-
#put(path, body_params = {}) ⇒ Object
The request bodythat will eventually be converted to JSON.
Constructor Details
#initialize(host, client) ⇒ HttpCommand
Returns a new instance of HttpCommand.
9 10 11 12 13 |
# File 'lib/timetree/http_command.rb', line 9 def initialize(host, client) @host = host @client = client @logger = TimeTree.configuration.logger end |
Instance Method Details
#delete(path, params = {}) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/timetree/http_command.rb', line 51 def delete(path, params = {}) @logger.debug "DELETE #{@host}#{path} params:#{params}" res = connection.delete path, params @client.update_ratelimit(res) @logger.debug "Response status:#{res.status}, body:#{res.body}" res end |
#get(path, params = {}) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/timetree/http_command.rb', line 17 def get(path, params = {}) @logger.info "GET #{connection.build_url("#{@host}#{path}", params)}" res = connection.get path, params @client.update_ratelimit(res) @logger.debug "Response status:#{res.status}, body:#{res.body}" res end |
#post(path, body_params = {}, &block) ⇒ Object
The request bodythat will eventually be converted to JSON.
28 29 30 31 32 33 34 35 |
# File 'lib/timetree/http_command.rb', line 28 def post(path, body_params = {}, &block) @logger.debug "POST #{@host}#{path} body:#{body_params}" headers = {'Content-Type' => 'application/json'} res = connection.run_request :post, path, body_params.to_json, headers, &block @client.update_ratelimit(res) @logger.debug "Response status:#{res.status}, body:#{res.body}" res end |
#put(path, body_params = {}) ⇒ Object
The request bodythat will eventually be converted to JSON.
40 41 42 43 44 45 46 47 |
# File 'lib/timetree/http_command.rb', line 40 def put(path, body_params = {}) @logger.debug "PUT #{@host}#{path} body:#{body_params}" headers = {'Content-Type' => 'application/json'} res = connection.run_request :put, path, body_params.to_json, headers @client.update_ratelimit(res) @logger.debug "Response status:#{res.status}, body:#{res.body}" res end |