lib/apitool/client/apitool_client.rb in apitool-client-0.0.2 vs lib/apitool/client/apitool_client.rb in apitool-client-0.0.3
- old
+ new
@@ -33,50 +33,54 @@
)
end
def get(path, options = {})
get_connection[request_uri(path)].get(headers) { |response, request, result, &block|
- @response = response
- @request = request
- @result = result
+ _update(response, request, result)
yield response, request, result if block_given?
}
end
def post(path, parameters)
get_connection[request_uri(path)].post(parameters.to_json, headers) { |response, request, result, &block|
- @response = response
- @request = request
- @result = result
+ _update(response, request, result)
yield response, request, result if block_given?
}
end
def put(path, parameters)
get_connection[request_uri(path)].put(parameters.to_json, headers) { |response, request, result, &block|
- @response = response
- @request = request
- @result = result
+ _update(response, request, result)
yield response, request, result if block_given?
}
end
def delete(path)
get_connection[request_uri(path)].delete(headers) { |response, request, result, &block|
- @response = response
- @request = request
- @result = result
+ _update(response, request, result)
yield response, request, result if block_given?
}
end
def parse(data)
JSON.parse(data, symbolize_names: @symbolize)
end
private
+ def _update(_response, _request, _result)
+ @response = _response
+ @request = _request
+ @result = _result
+
+ log = "#{result} - #{request[:method].upcase} - #{request[:url]} - payload[#{request[:payload] || ''}]"
+ if response.present? and response.kind_of? Array and response[0].has_key?(:message)
+ log = log + " - error[#{response[0][:message] || ''} | #{response[0][:details] || ''}]"
+ end
+ logger.info log
+ end
+
def base_uri
if @ssl
"https://#{@host}:#{@port}"
else
"http://#{@host}:#{@port}"
@@ -91,8 +95,12 @@
{
content_type: :json,
accept: :json,
authorization: "Token token=#{@token}"
}
+ end
+
+ def logger
+ Apitool::Client.logger
end
end