Class: Ingenico::Direct::SDK::Logging::LogMessageBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/ingenico/direct/sdk/logging/log_message_builder.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_id) ⇒ LogMessageBuilder

Create a new LogMessageBuilder

Raises:

  • (ArgumentError)


18
19
20
21
22
# File 'lib/ingenico/direct/sdk/logging/log_message_builder.rb', line 18

def initialize(request_id)
  raise ArgumentError if request_id.nil? || request_id.empty?
  @request_id = request_id
  @headers = ''
end

Instance Attribute Details

#bodyString (readonly)

Request or response body as a string

Returns:

  • (String)

    the current value of body



10
11
12
# File 'lib/ingenico/direct/sdk/logging/log_message_builder.rb', line 10

def body
  @body
end

#content_typeString (readonly)

Content type of the body, generally ‘application/json’ or ‘text/html’

Returns:

  • (String)

    the current value of content_type



10
11
12
# File 'lib/ingenico/direct/sdk/logging/log_message_builder.rb', line 10

def content_type
  @content_type
end

#headersString (readonly)

Request or response headers in string form

Returns:

  • (String)

    the current value of headers



10
11
12
# File 'lib/ingenico/direct/sdk/logging/log_message_builder.rb', line 10

def headers
  @headers
end

#request_idString (readonly)

An identifier assigned to the request and response

Returns:

  • (String)

    the current value of request_id



10
11
12
# File 'lib/ingenico/direct/sdk/logging/log_message_builder.rb', line 10

def request_id
  @request_id
end

Instance Method Details

#add_headers(name, value) ⇒ Object

Adds a single header to the #headers string



25
26
27
28
# File 'lib/ingenico/direct/sdk/logging/log_message_builder.rb', line 25

def add_headers(name, value)
  @headers += ', ' unless @headers.empty?
  @headers += "#{name}='#{LoggingUtil.obfuscate_header(name, value)}'"
end

#get_messageObject

Constructs and returns the log message as a string.

Raises:

  • (NotImplementedError)


40
41
42
# File 'lib/ingenico/direct/sdk/logging/log_message_builder.rb', line 40

def get_message
  raise NotImplementedError, "#{self.class.name}#get_message() is not implemented."
end

#set_body(body, content_type) ⇒ Object

Parameters:

  • body (String)

    the message body

  • content_type (String)

    the content type of the body



34
35
36
37
# File 'lib/ingenico/direct/sdk/logging/log_message_builder.rb', line 34

def set_body(body, content_type)
  @body = LoggingUtil.obfuscate_body(body)
  @content_type = content_type
end

#to_sObject



44
45
46
47
48
# File 'lib/ingenico/direct/sdk/logging/log_message_builder.rb', line 44

def to_s
  self.class == LogMessageBuilder ?
      super.to_s :
      get_message
end