Class: Fopost::HTTP::Response

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

Overview

What a Transport hands back: the raw status, headers, and body.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status:, body: '', headers: {}) ⇒ Response

Returns a new instance of Response.



9
10
11
12
13
# File 'lib/fopost/http/response.rb', line 9

def initialize(status:, body: '', headers: {})
  @status = status
  @body = body.to_s
  @headers = headers.each_with_object({}) { |(k, v), out| out[k.to_s.downcase] = v }
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



7
8
9
# File 'lib/fopost/http/response.rb', line 7

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers.



7
8
9
# File 'lib/fopost/http/response.rb', line 7

def headers
  @headers
end

#statusObject (readonly)

Returns the value of attribute status.



7
8
9
# File 'lib/fopost/http/response.rb', line 7

def status
  @status
end

Instance Method Details

#header(name) ⇒ Object



19
20
21
# File 'lib/fopost/http/response.rb', line 19

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

#success?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/fopost/http/response.rb', line 15

def success?
  status >= 200 && status < 300
end