Class: Worldline::Acquiring::SDK::Communication::RequestHeader
- Inherits:
-
Object
- Object
- Worldline::Acquiring::SDK::Communication::RequestHeader
- Defined in:
- lib/worldline/acquiring/sdk/communication/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 RequestHeader 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.
13 14 15 16 17 18 19 |
# File 'lib/worldline/acquiring/sdk/communication/request_header.rb', line 13 def initialize(name, value) if name.nil? || name.strip.empty? raise ArgumentError.new('name is required') end @name = name @value = normalize_value(value) end |
Instance Attribute Details
#name ⇒ String (readonly)
HTTP header name
10 11 12 |
# File 'lib/worldline/acquiring/sdk/communication/request_header.rb', line 10 def name @name end |
#value ⇒ String (readonly)
HTTP header value
10 11 12 |
# File 'lib/worldline/acquiring/sdk/communication/request_header.rb', line 10 def value @value end |
Class Method Details
.get_header(headers, header_name) ⇒ Object
Return the Worldline::Acquiring::SDK::Communication::RequestHeader that goes by the given header_name, If this Response does not contain a header with the given name, return nil instead
30 31 32 33 34 35 36 37 |
# File 'lib/worldline/acquiring/sdk/communication/request_header.rb', line 30 def self.get_header(headers, header_name) selected_headers = headers.select { |h| h.name == header_name } if selected_headers.nil? || selected_headers.length == 0 return nil else return selected_headers[0] end 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
41 42 43 44 45 46 47 48 49 |
# File 'lib/worldline/acquiring/sdk/communication/request_header.rb', line 41 def self.get_header_value(headers, header_name) header = get_header(headers, header_name) return ( if header.nil? nil else header.value end) end |
Instance Method Details
#to_s ⇒ Object
24 25 26 |
# File 'lib/worldline/acquiring/sdk/communication/request_header.rb', line 24 def to_s "#{name}:#{value}" end |