class TimeTree::HttpCommand
Command for HTTP request.
Public Class Methods
new(host, client)
click to toggle source
# File lib/timetree/http_command.rb, line 9 def initialize(host, client) @host = host @client = client @logger = TimeTree.configuration.logger end
Public Instance Methods
delete(path, params = {})
click to toggle source
@param path [String] String or URI to access. @param params [Hash] Hash of URI query unencoded key/value pairs.
# 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 = {})
click to toggle source
@param path [String] String or URI to access. @param params [Hash] Hash of URI query unencoded key/value pairs.
# 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)
click to toggle source
@param path [String] String or URI to access. @param body_params [Hash] The request bodythat will eventually be converted to JSON.
# 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 = {})
click to toggle source
@param path [String] String or URI to access. @param body_params [Hash] The request bodythat will eventually be converted to JSON.
# 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
Private Instance Methods
base_request_headers()
click to toggle source
# File lib/timetree/http_command.rb, line 70 def base_request_headers { 'Accept' => 'application/vnd.timetree.v1+json', 'Authorization' => "Bearer #{@client.token}" } end
connection()
click to toggle source
# File lib/timetree/http_command.rb, line 61 def connection Faraday.new( url: @host, headers: base_request_headers ) do |builder| builder.response :json, parser_options: {symbolize_names: true}, content_type: /\bjson$/ end end