Class: Ingenico::Connect::SDK::RequestHeader

Inherits:
Object
  • Object
show all
Defined in:
lib/ingenico/connect/sdk/request_header.rb

Overview

Represents HTTP request headers Each header is immutable has a #name and #value attribute

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, value) ⇒ RequestHeader

Create a new header using the name and value given as parameters.



11
12
13
14
15
16
17
# File 'lib/ingenico/connect/sdk/request_header.rb', line 11

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

#nameString (readonly)

HTTP header name

Returns:

  • (String)

    the current value of name



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

def name
  @name
end

#valueString (readonly)

HTTP header value

Returns:

  • (String)

    the current value of value



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

def value
  @value
end

Class Method Details

.get_header(headers, header_name) ⇒ Object

Return the Ingenico::Connect::SDK::ResponseHeader that goes by the given header_name, If this Response does not contain a header with the given name, return nil instead



28
29
30
31
32
33
34
35
# File 'lib/ingenico/connect/sdk/request_header.rb', line 28

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



39
40
41
42
# File 'lib/ingenico/connect/sdk/request_header.rb', line 39

def self.get_header_value(headers, header_name)
    header = get_header(headers, header_name)
    return (if header.nil? then nil else header.value end)
end

Instance Method Details

#to_sObject



22
23
24
# File 'lib/ingenico/connect/sdk/request_header.rb', line 22

def to_s
  "#{name}:#{value}"
end