Class: Ingenico::Direct::SDK::RequestHeader
- Inherits:
-
Object
- Object
- Ingenico::Direct::SDK::RequestHeader
- Defined in:
- lib/ingenico/direct/sdk/request_header.rb
Overview
Represents HTTP request headers Each header is immutable has a #name and #value attribute
Instance Attribute Summary collapse
-
#name ⇒ String
readonly
HTTP header name.
-
#value ⇒ String
readonly
HTTP header value.
Class Method Summary collapse
-
.get_header(headers, header_name) ⇒ Object
Return the ResponseHeader that goes by the given header_name, If this Response does not contain a header with the given name, return nil instead.
-
.get_header_value(headers, header_name) ⇒ Object
Returns the header value of the header that goes by the given header_name, If this response does not contain a header with the given name, return nil instead.
Instance Method Summary collapse
-
#initialize(name, value) ⇒ RequestHeader
constructor
Create a new header using the name and value given as parameters.
- #to_s ⇒ Object
Constructor Details
#initialize(name, value) ⇒ RequestHeader
Create a new header using the name and value given as parameters.
11 12 13 14 15 |
# File 'lib/ingenico/direct/sdk/request_header.rb', line 11 def initialize(name, value) raise ArgumentError, 'name is required' if name.nil? || name.strip.empty? @name = name @value = normalize_value(value) end |
Instance Attribute Details
#name ⇒ String (readonly)
HTTP header name
8 9 10 |
# File 'lib/ingenico/direct/sdk/request_header.rb', line 8 def name @name end |
#value ⇒ String (readonly)
HTTP header value
8 9 10 |
# File 'lib/ingenico/direct/sdk/request_header.rb', line 8 def value @value end |
Class Method Details
.get_header(headers, header_name) ⇒ Object
Return the Ingenico::Direct::SDK::ResponseHeader that goes by the given header_name, If this Response does not contain a header with the given name, return nil instead
26 27 28 29 30 31 |
# File 'lib/ingenico/direct/sdk/request_header.rb', line 26 def self.get_header(headers, header_name) selected_headers = headers.select { |h| h.name == header_name } return selected_headers&.length.positive? ? selected_headers[0] : nil end |
.get_header_value(headers, header_name) ⇒ Object
Returns the header value of the header that goes by the given header_name, If this response does not contain a header with the given name, return nil instead
35 36 37 |
# File 'lib/ingenico/direct/sdk/request_header.rb', line 35 def self.get_header_value(headers, header_name) return get_header(headers, header_name)&.value end |
Instance Method Details
#to_s ⇒ Object
20 21 22 |
# File 'lib/ingenico/direct/sdk/request_header.rb', line 20 def to_s "#{name}:#{value}" end |