Class: Basecamp::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/basecamp/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.



824
825
826
827
828
# File 'lib/basecamp/http.rb', line 824

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

Instance Attribute Details

#bodyString (readonly)

Returns response body.

Returns:

  • (String)

    response body



816
817
818
# File 'lib/basecamp/http.rb', line 816

def body
  @body
end

#headersHash (readonly)

Returns response headers.

Returns:

  • (Hash)

    response headers



822
823
824
# File 'lib/basecamp/http.rb', line 822

def headers
  @headers
end

#statusInteger (readonly)

Returns HTTP status code.

Returns:

  • (Integer)

    HTTP status code



819
820
821
# File 'lib/basecamp/http.rb', line 819

def status
  @status
end

Instance Method Details

#jsonHash, Array

Parses the response body as JSON, normalizing Person-shaped objects.

Returns:

  • (Hash, Array)


832
833
834
835
836
837
838
839
# File 'lib/basecamp/http.rb', line 832

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

#success?Boolean

Returns whether the response was successful (2xx).

Returns:

  • (Boolean)


843
844
845
# File 'lib/basecamp/http.rb', line 843

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