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 "Server: #{@uri}"
log.info "#{http_method.to_s.upcase} #{path}"
log.debug "Params: #{inspect_data(params)}"
log.debug "Headers: #{inspect_data(headers)}"
args << headers if headers
if dry_run?
empty_response = ApipieBindings::Example.new('', '', '', 200, '')
ex = options[:fake_response ] || empty_response
response = create_fake_response(ex.status, ex.response, http_method, path, args)
else
begin
apidoc_without_auth = (path =~ /\/apidoc\//) && !@apidoc_authenticated
authenticate = options[:with_authentication].nil? ? !apidoc_without_auth : options[:with_authentication]
client = authenticate ? authenticated_client : unauthenticated_client
response = call_client(client, path, args)
update_cache(response.headers[:apipie_checksum])
rescue => e
clear_credentials if e.is_a? RestClient::Unauthorized
log.debug e.message + "\n" +
inspect_data(e.respond_to?(:response) ? process_data(e.response) : e)
raise
end
end
result = options[:response] == :raw ? response : process_data(response)
log.debug "Response: %s" % (options[:reduce_response_log] ? "Received OK" : inspect_data(result))
log.debug "Response headers: #{inspect_data(response.headers)}" if response.respond_to?(:headers)
result
end