Class: Whoosh::HTTP::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Response.



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

def initialize(status:, body:, headers: {})
  @status = status
  @body = body
  @headers = headers
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



9
10
11
# File 'lib/whoosh/http/response.rb', line 9

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers.



9
10
11
# File 'lib/whoosh/http/response.rb', line 9

def headers
  @headers
end

#statusObject (readonly)

Returns the value of attribute status.



9
10
11
# File 'lib/whoosh/http/response.rb', line 9

def status
  @status
end

Instance Method Details

#jsonObject



17
18
19
# File 'lib/whoosh/http/response.rb', line 17

def json
  @json ||= JSON.parse(@body)
end

#ok?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/whoosh/http/response.rb', line 21

def ok?
  @status >= 200 && @status < 300
end