def http_call(http_method, path, params={}, headers={}, options={})
headers ||= { }
args = [http_method]
if %w[post put].include?(http_method.to_s)
if ((headers.include?(:content_type)) and (headers[:content_type] == "multipart/form-data"))
args << params
else
args << params.to_json
end
else
headers[:params] = params if params
end
log.info "#{http_method.to_s.upcase} #{path}"
log.debug "Params: #{params.ai}"
log.debug "Headers: #{headers.ai}"
args << headers if headers
if dry_run?
empty_response = ApipieBindings::Example.new('', '', '', 200, '')
ex = options[:fake_response ] || empty_response
net_http_resp = Net::HTTPResponse.new(1.0, ex.status, "")
response = RestClient::Response.create(ex.response, net_http_resp, args)
else
begin
response = @client[path].send(*args)
update_cache(response.headers[:apipie_checksum])
rescue => e
log.debug e.message + "\n" +
(e.respond_to?(:response) ? process_data(e.response).ai : e.ai)
raise
end
end
result = options[:response] == :raw ? response : process_data(response)
log.debug "Response: %s" % (options[:reduce_response_log] ? "Received OK" : result.ai)
log.debug "Response headers: #{response.headers.ai}" if response.respond_to?(:headers)
result
end