class Delighted::HTTPResponse

Attributes

body[R]
headers[R]
status_code[R]

Public Class Methods

new(raw_status_code, raw_headers, raw_body) click to toggle source
# File lib/delighted/http_response.rb, line 5
def initialize(raw_status_code, raw_headers, raw_body)
  @status_code = raw_status_code.to_i
  @headers = raw_headers
  @body = raw_body
end

Public Instance Methods

content_type() click to toggle source
# File lib/delighted/http_response.rb, line 11
def content_type
  get_header_value("content-type")
end
retry_after() click to toggle source
# File lib/delighted/http_response.rb, line 20
def retry_after
  if value = get_header_value("retry-after")
    value.to_i
  end
end

Private Instance Methods

get_header_value(key) click to toggle source

Get value from header. Takes care of:

  • Unwrapping multiple values.

  • Handling casing difference in header name.

# File lib/delighted/http_response.rb, line 32
def get_header_value(key)
  _key, value = @headers.detect { |k, _v| k.to_s.downcase == key.to_s.downcase }

  if value
    values = Utils.wrap_array(value)

    if values.size == 1
      values[0]
    else
      values
    end
  end
end