Class: Fizzy::Response

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

Overview

Wraps an HTTP response.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Response.



390
391
392
393
394
# File 'lib/fizzy/http.rb', line 390

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

Instance Attribute Details

#bodyString (readonly)

Returns response body.

Returns:

  • (String)

    response body



382
383
384
# File 'lib/fizzy/http.rb', line 382

def body
  @body
end

#headersHash (readonly)

Returns response headers.

Returns:

  • (Hash)

    response headers



388
389
390
# File 'lib/fizzy/http.rb', line 388

def headers
  @headers
end

#statusInteger (readonly)

Returns HTTP status code.

Returns:

  • (Integer)

    HTTP status code



385
386
387
# File 'lib/fizzy/http.rb', line 385

def status
  @status
end

Instance Method Details

#jsonHash, Array

Parses the response body as JSON.

Returns:

  • (Hash, Array)


398
399
400
401
402
403
# File 'lib/fizzy/http.rb', line 398

def json
  @json ||= begin
    Security.check_body_size!(@body, Security::MAX_RESPONSE_BODY_BYTES)
    JSON.parse(@body)
  end
end

#success?Boolean

Returns whether the response was successful (2xx).

Returns:

  • (Boolean)


407
408
409
# File 'lib/fizzy/http.rb', line 407

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