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
Public Class Methods
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
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
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
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
# File lib/ingenico/connect/sdk/response_header.rb, line 20 def to_s "#{name}:#{value}" end
Private Instance Methods
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