class Ingenico::Connect::SDK::ResponseHeader

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

@attr_reader [String] name HTTP header name @attr_reader [String] value HTTP header value

Attributes

name[R]
value[R]

Public Class Methods

get_disposition_filename(headers) click to toggle source

Returns the value of the filename parameter of the Content-Disposition header from parameter headers If this Response does not contain a header with the given name, return nil instead

# File lib/ingenico/connect/sdk/response_header.rb, line 45
def self.get_disposition_filename(headers)
  header_value = get_header_value(headers, "Content-Disposition")
  unless header_value.nil?
    if header_value =~ /(?:^|;)\s*filename\s*=\s*(.*?)\s*(?:;|$)i/
      return trim_quotes($2)
    end
  end

  return nil
end
get_header(headers, header_name) click to toggle source

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

# File lib/ingenico/connect/sdk/response_header.rb, line 26
def self.get_header(headers, header_name)
  selected_headers = headers.select { |h| h.name.casecmp(header_name) == 0 }
  if selected_headers.nil? || selected_headers.length == 0
    return nil
  else
    return selected_headers[0]
  end
end
get_header_value(headers, header_name) click to toggle source

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

# File lib/ingenico/connect/sdk/response_header.rb, line 37
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
new(name, value) click to toggle source

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

# File lib/ingenico/connect/sdk/response_header.rb, line 11
def initialize(name, value)
  raise ArgumentError.new('name is required') if name.nil? or name.strip.empty?
  @name = name
  @value = value
end

Public Instance Methods

to_s() click to toggle source
# File lib/ingenico/connect/sdk/response_header.rb, line 20
def to_s
  "#{name}:#{value}"
end

Private Instance Methods

trim_quotes(filename) click to toggle source

Trims the single or double quotes at the beginning and end of parameter filename if they exist If they don't exist, it returns the original filename instead

# File lib/ingenico/connect/sdk/response_header.rb, line 60
def trim_quotes(filename)
  unless filename.length < 2
    if ( filename.chars.first == '\'' && filename.chars.last == '\"' ) ||
        ( filename.chars.first == '"' && filename.chars.last == '"' )
      return filename[1...-1]
    end
  end
  return filename
end