lib/flexirest/request.rb in flexirest-1.10.11 vs lib/flexirest/request.rb in flexirest-1.10.12
- old
+ new
@@ -182,10 +182,18 @@
else
@object.class.verbose
end
end
+ def quiet?
+ if object_is_class?
+ @object.quiet
+ else
+ @object.class.quiet
+ end
+ end
+
def translator
if object_is_class?
@object.translator
else
@object.class.translator
@@ -224,11 +232,11 @@
def call(explicit_parameters=nil)
@instrumentation_name = "#{class_name}##{@method[:name]}"
result = nil
cached = nil
- ActiveSupport::Notifications.instrument("request_call.flexirest", :name => @instrumentation_name) do
+ ActiveSupport::Notifications.instrument("request_call.flexirest", :name => @instrumentation_name, quiet: quiet?) do
@explicit_parameters = explicit_parameters
@body = nil
prepare_params
prepare_url
fake = @method[:options][:fake]
@@ -242,11 +250,11 @@
elsif @object.new.respond_to?(fake)
fake = @object.new.send(fake)
elsif @object.class.new.respond_to?(fake)
fake = @object.class.new.send(fake)
end
- Flexirest::Logger.debug " \033[1;4;32m#{Flexirest.name}\033[0m #{@instrumentation_name} - Faked response found"
+ Flexirest::Logger.debug " \033[1;4;32m#{Flexirest.name}\033[0m #{@instrumentation_name} - Faked response found" unless quiet?
content_type = @method[:options][:fake_content_type] || "application/json"
return handle_response(OpenStruct.new(status:200, body:fake, response_headers:{"X-ARC-Faked-Response" => "true", "Content-Type" => content_type}))
end
if object_is_class?
callback_result = @object.send(:_callback_request, :before, @method[:name], self)
@@ -258,17 +266,17 @@
end
append_get_parameters
prepare_request_body
self.original_url = self.url
- cached = original_object_class.read_cached_response(self)
+ cached = original_object_class.read_cached_response(self, quiet?)
if cached && !cached.is_a?(String)
if cached.expires && cached.expires > Time.now
- Flexirest::Logger.debug " \033[1;4;32m#{Flexirest.name}\033[0m #{@instrumentation_name} - Absolutely cached copy found"
+ Flexirest::Logger.debug " \033[1;4;32m#{Flexirest.name}\033[0m #{@instrumentation_name} - Absolutely cached copy found" unless quiet?
return handle_cached_response(cached)
elsif cached.etag.to_s != "" #present? isn't working for some reason
- Flexirest::Logger.debug " \033[1;4;32m#{Flexirest.name}\033[0m #{@instrumentation_name} - Etag cached copy found with etag #{cached.etag}"
+ Flexirest::Logger.debug " \033[1;4;32m#{Flexirest.name}\033[0m #{@instrumentation_name} - Etag cached copy found with etag #{cached.etag}" unless quiet?
etag = cached.etag
end
end
response = (
@@ -562,13 +570,13 @@
inject_basic_auth_in_url(base_url)
end
connection = Flexirest::ConnectionManager.get_connection(base_url)
end
if @method[:options][:direct]
- Flexirest::Logger.info " \033[1;4;32m#{Flexirest.name}\033[0m #{@instrumentation_name} - Requesting #{@url}"
+ Flexirest::Logger.info " \033[1;4;32m#{Flexirest.name}\033[0m #{@instrumentation_name} - Requesting #{@url}" unless quiet?
else
- Flexirest::Logger.info " \033[1;4;32m#{Flexirest.name}\033[0m #{@instrumentation_name} - Requesting #{connection.base_url}#{@url}"
+ Flexirest::Logger.info " \033[1;4;32m#{Flexirest.name}\033[0m #{@instrumentation_name} - Requesting #{connection.base_url}#{@url}" unless quiet?
end
if verbose?
Flexirest::Logger.debug "Flexirest Verbose Log:"
Flexirest::Logger.debug " Request"
@@ -632,11 +640,11 @@
@response.body = "{}"
end
if cached && response.status == 304
Flexirest::Logger.debug " \033[1;4;32m#{Flexirest.name}\033[0m #{@instrumentation_name}" +
- ' - Etag copy is the same as the server'
+ ' - Etag copy is the same as the server' unless quiet?
return handle_cached_response(cached)
end
if (200..399).include?(status)
if status == 204 || (@response.body.blank? && @method[:options][:ignore_empty_response])
@@ -645,12 +653,12 @@
if @method[:options][:plain]
return @response = Flexirest::PlainResponse.from_response(@response)
elsif is_json_response? || is_xml_response?
if @response.respond_to?(:proxied) && @response.proxied
- Flexirest::Logger.debug " \033[1;4;32m#{Flexirest.name}\033[0m #{@instrumentation_name} - Response was proxied, unable to determine size"
+ Flexirest::Logger.debug " \033[1;4;32m#{Flexirest.name}\033[0m #{@instrumentation_name} - Response was proxied, unable to determine size" unless quiet?
else
- Flexirest::Logger.debug " \033[1;4;32m#{Flexirest.name}\033[0m #{@instrumentation_name} - Response received #{@response.body.size} bytes"
+ Flexirest::Logger.debug " \033[1;4;32m#{Flexirest.name}\033[0m #{@instrumentation_name} - Response received #{@response.body.size} bytes" unless quiet?
end
result = generate_new_object(ignore_root: ignore_root, ignore_xml_root: @method[:options][:ignore_xml_root])
# TODO: Cleanup when ignore_xml_root is removed
else
raise ResponseParseException.new(status:status, body:@response.body, headers: @response.headers)