class Ingenico::Connect::SDK::Logging::LogMessageBuilder

Abstract class used to construct a message describing a request or response.

@attr_reader [String] request_id An identifier assigned to the request and response @attr_reader [String] headers Request or response headers in string form @attr_reader [String] body Request or response body as a string @attr_reader [String] content_type Content type of the body, generally 'application/json' or 'text/html'

Attributes

body[R]
content_type[R]
headers[R]
request_id[R]

Public Class Methods

new(request_id) click to toggle source

Create a new LogMessageBuilder

# File lib/ingenico/connect/sdk/logging/log_message_builder.rb, line 18
def initialize(request_id)
  raise ArgumentError if request_id.nil? or request_id.empty?
  @request_id = request_id
  @headers = ''
end

Public Instance Methods

add_headers(name, value) click to toggle source

Adds a single header to the headers string

# File lib/ingenico/connect/sdk/logging/log_message_builder.rb, line 25
def add_headers(name, value)
  @headers += ', ' if @headers.length > 0
  @headers += name + '="'
  @headers += LoggingUtil.obfuscate_header(name, value) unless value.nil?
  @headers += '"'
end
get_message() click to toggle source

Constructs and returns the log message as a string.

# File lib/ingenico/connect/sdk/logging/log_message_builder.rb, line 46
def get_message
  raise NotImplementedError.new("#{self.class.name}#get_message() is not implemented.")
end
is_binary(content_type) click to toggle source

Returns whether or not the content type is binary

# File lib/ingenico/connect/sdk/logging/log_message_builder.rb, line 64
def is_binary(content_type)
  if content_type.nil?
    return false
  else
    content_type = content_type.downcase
    return !(content_type.start_with?("text/") || content_type.include?("json") || content_type.include?("xml"))
  end
end
set_body(body, content_type) click to toggle source

@param body [String] the message body @param content_type [String] the content type of the body

# File lib/ingenico/connect/sdk/logging/log_message_builder.rb, line 36
def set_body(body, content_type)
  if is_binary(content_type)
    @body = "<binary content>"
  else
    @body = LoggingUtil.obfuscate_body(body)
  end
  @content_type = content_type
end
to_s() click to toggle source
Calls superclass method
# File lib/ingenico/connect/sdk/logging/log_message_builder.rb, line 50
def to_s
  if self.class == LogMessageBuilder
    return super.to_s
  else
    return get_message
  end
end

Protected Instance Methods

empty_if_null(value) click to toggle source

Returns an empty string if the parameter is nil, and returns the parameter itself otherwise

# File lib/ingenico/connect/sdk/logging/log_message_builder.rb, line 59
          def empty_if_null(value)
  value.nil? ? '' : value
end