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.
-
#body_obfuscator ⇒ OnlinePayments::SDK::Logging::Obfuscation::BodyObfuscator
readonly
The current value of body_obfuscator.
-
#content_type ⇒ String
readonly
Content type of the body, generally ‘application/json’ or ‘text/html’.
-
#header_obfuscator ⇒ OnlinePayments::SDK::Logging::Obfuscation::HeaderObfuscator
readonly
The current value of header_obfuscator.
-
#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 ⇒ String
Constructs and returns the log message as a string.
-
#initialize(request_id, body_obfuscator = Obfuscation::BodyObfuscator.default_obfuscator, header_obfuscator = Obfuscation::HeaderObfuscator.default_obfuscator) ⇒ LogMessageBuilder
constructor
Create a new LogMessageBuilder.
-
#is_binary(content_type) ⇒ Object
Returns whether or not the content type is binary.
- #set_body(body, content_type) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(request_id, body_obfuscator = Obfuscation::BodyObfuscator.default_obfuscator, header_obfuscator = Obfuscation::HeaderObfuscator.default_obfuscator) ⇒ LogMessageBuilder
Create a new LogMessageBuilder
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/onlinepayments/sdk/logging/log_message_builder.rb', line 25 def initialize(request_id, body_obfuscator = Obfuscation::BodyObfuscator.default_obfuscator, header_obfuscator = Obfuscation::HeaderObfuscator.default_obfuscator) raise ArgumentError if request_id.nil? or request_id.empty? raise ArgumentError if body_obfuscator.nil? raise ArgumentError if header_obfuscator.nil? @request_id = request_id @headers = '' @body_obfuscator = body_obfuscator @header_obfuscator = header_obfuscator end |
Instance Attribute Details
#body ⇒ String (readonly)
Request or response body as a string
15 16 17 |
# File 'lib/onlinepayments/sdk/logging/log_message_builder.rb', line 15 def body @body end |
#body_obfuscator ⇒ OnlinePayments::SDK::Logging::Obfuscation::BodyObfuscator (readonly)
Returns the current value of body_obfuscator.
15 16 17 |
# File 'lib/onlinepayments/sdk/logging/log_message_builder.rb', line 15 def body_obfuscator @body_obfuscator end |
#content_type ⇒ String (readonly)
Content type of the body, generally ‘application/json’ or ‘text/html’
15 16 17 |
# File 'lib/onlinepayments/sdk/logging/log_message_builder.rb', line 15 def content_type @content_type end |
#header_obfuscator ⇒ OnlinePayments::SDK::Logging::Obfuscation::HeaderObfuscator (readonly)
Returns the current value of header_obfuscator.
15 16 17 |
# File 'lib/onlinepayments/sdk/logging/log_message_builder.rb', line 15 def header_obfuscator @header_obfuscator end |
#headers ⇒ String (readonly)
Request or response headers in string form
15 16 17 |
# File 'lib/onlinepayments/sdk/logging/log_message_builder.rb', line 15 def headers @headers end |
#request_id ⇒ String (readonly)
An identifier assigned to the request and response
15 16 17 |
# File 'lib/onlinepayments/sdk/logging/log_message_builder.rb', line 15 def request_id @request_id end |
Instance Method Details
#add_headers(name, value) ⇒ Object
Adds a single header to the #headers string
38 39 40 41 42 43 |
# File 'lib/onlinepayments/sdk/logging/log_message_builder.rb', line 38 def add_headers(name, value) @headers += ', ' if @headers.length > 0 @headers += name + '="' @headers += @header_obfuscator.obfuscate_header(name, value) unless value.nil? @headers += '"' end |
#get_message ⇒ String
Constructs and returns the log message as a string.
60 61 62 |
# File 'lib/onlinepayments/sdk/logging/log_message_builder.rb', line 60 def raise NotImplementedError.new("#{self.class.name}#get_message() is not implemented.") end |
#is_binary(content_type) ⇒ Object
Returns whether or not the content type is binary
78 79 80 81 82 83 84 85 |
# File 'lib/onlinepayments/sdk/logging/log_message_builder.rb', line 78 def is_binary(content_type) if content_type.nil? false else content_type = content_type.downcase !(content_type.start_with?("text/") || content_type.include?("json") || content_type.include?("xml")) end end |
#set_body(body, content_type) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/onlinepayments/sdk/logging/log_message_builder.rb', line 49 def set_body(body, content_type) if is_binary(content_type) @body = "<binary content>" else @body = @body_obfuscator.obfuscate_body(body) end @content_type = content_type end |
#to_s ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/onlinepayments/sdk/logging/log_message_builder.rb', line 64 def to_s if self.class == LogMessageBuilder super.to_s else end end |