Class: Api2Convert::Http::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/api2convert/http/response.rb

Overview

A transport-agnostic HTTP response. Headers are stored with downcased keys so #header lookups are case-insensitive regardless of the sender.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status, headers, body, reason = "") ⇒ Response

Returns a new instance of Response.



10
11
12
13
14
15
# File 'lib/api2convert/http/response.rb', line 10

def initialize(status, headers, body, reason = "")
  @status = status
  @headers = headers || {}
  @body = body || ""
  @reason = reason || ""
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



8
9
10
# File 'lib/api2convert/http/response.rb', line 8

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers.



8
9
10
# File 'lib/api2convert/http/response.rb', line 8

def headers
  @headers
end

#reasonObject (readonly)

Returns the value of attribute reason.



8
9
10
# File 'lib/api2convert/http/response.rb', line 8

def reason
  @reason
end

#statusObject (readonly)

Returns the value of attribute status.



8
9
10
# File 'lib/api2convert/http/response.rb', line 8

def status
  @status
end

Instance Method Details

#header(name) ⇒ Object

Case-insensitive header lookup. Returns nil when absent.



18
19
20
# File 'lib/api2convert/http/response.rb', line 18

def header(name)
  @headers[name.to_s.downcase]
end