Class: Ingenico::Connect::SDK::Logging::LogMessageBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/ingenico/connect/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(requestId) ⇒ LogMessageBuilder

Create a new LogMessageBuilder

Raises:

  • (ArgumentError)


20
21
22
23
24
# File 'lib/ingenico/connect/sdk/logging/log_message_builder.rb', line 20

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

Instance Attribute Details

#bodyObject (readonly)

Request or response body as a string



14
15
16
# File 'lib/ingenico/connect/sdk/logging/log_message_builder.rb', line 14

def body
  @body
end

#content_typeObject (readonly)

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



17
18
19
# File 'lib/ingenico/connect/sdk/logging/log_message_builder.rb', line 17

def content_type
  @content_type
end

#headersObject (readonly)

Request or response headers in string form



11
12
13
# File 'lib/ingenico/connect/sdk/logging/log_message_builder.rb', line 11

def headers
  @headers
end

#request_idObject (readonly)

An identifier assigned to the request and response



8
9
10
# File 'lib/ingenico/connect/sdk/logging/log_message_builder.rb', line 8

def request_id
  @request_id
end

Instance Method Details

#add_headers(name, value) ⇒ Object

Adds a single header to the #headers string



27
28
29
30
31
32
# File 'lib/ingenico/connect/sdk/logging/log_message_builder.rb', line 27

def add_headers(name, value)
  @headers += ', ' if @headers.length > 0
  @headers += name + '="'
  @headers += LoggingUtil.obfuscate_header(name, value) unless value.nil?
  @headers += '"'
end

#get_messageObject

Constructs and returns the log message as a string.

Raises:

  • (NotImplementedError)


43
44
45
# File 'lib/ingenico/connect/sdk/logging/log_message_builder.rb', line 43

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

#set_body(body, content_type) ⇒ Object

Sets the body of this message to the parameter body.

body

The message body

content_type

The content type of the body



37
38
39
40
# File 'lib/ingenico/connect/sdk/logging/log_message_builder.rb', line 37

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

#to_sObject



47
48
49
50
51
52
53
# File 'lib/ingenico/connect/sdk/logging/log_message_builder.rb', line 47

def to_s
  if self.class == LogMessageBuilder
    return super.to_s
  else
    return get_message
  end
end