Class: OnlinePayments::SDK::Logging::LogMessageBuilder
- Inherits:
-
Object
- Object
- OnlinePayments::SDK::Logging::LogMessageBuilder
- Defined in:
- lib/onlinepayments/sdk/logging/log_message_builder.rb
Overview
Abstract class used to construct a message describing a request or response.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#body ⇒ String
readonly
Request or response body as a string.
-
#content_type ⇒ String
readonly
Content type of the body, generally ‘application/json’ or ‘text/html’.
-
#headers ⇒ String
readonly
Request or response headers in string form.
-
#request_id ⇒ String
readonly
An identifier assigned to the request and response.
Instance Method Summary collapse
-
#add_headers(name, value) ⇒ Object
Adds a single header to the #headers string.
-
#get_message ⇒ Object
Constructs and returns the log message as a string.
-
#initialize(request_id) ⇒ LogMessageBuilder
constructor
Create a new LogMessageBuilder.
- #set_body(body, content_type) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(request_id) ⇒ LogMessageBuilder
Create a new LogMessageBuilder
18 19 20 21 22 |
# File 'lib/onlinepayments/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
#body ⇒ String (readonly)
Request or response body as a string
10 11 12 |
# File 'lib/onlinepayments/sdk/logging/log_message_builder.rb', line 10 def body @body end |
#content_type ⇒ String (readonly)
Content type of the body, generally ‘application/json’ or ‘text/html’
10 11 12 |
# File 'lib/onlinepayments/sdk/logging/log_message_builder.rb', line 10 def content_type @content_type end |
#headers ⇒ String (readonly)
Request or response headers in string form
10 11 12 |
# File 'lib/onlinepayments/sdk/logging/log_message_builder.rb', line 10 def headers @headers end |
#request_id ⇒ String (readonly)
An identifier assigned to the request and response
10 11 12 |
# File 'lib/onlinepayments/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/onlinepayments/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_message ⇒ Object
Constructs and returns the log message as a string.
40 41 42 |
# File 'lib/onlinepayments/sdk/logging/log_message_builder.rb', line 40 def raise NotImplementedError, "#{self.class.name}#get_message() is not implemented." end |
#set_body(body, content_type) ⇒ Object
34 35 36 37 |
# File 'lib/onlinepayments/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_s ⇒ Object
44 45 46 47 48 |
# File 'lib/onlinepayments/sdk/logging/log_message_builder.rb', line 44 def to_s self.class == LogMessageBuilder ? super.to_s : end |