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.



861
862
863
864
865
# File 'lib/basecamp/http.rb', line 861

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

Instance Attribute Details

#bodyString (readonly)

Returns response body.

Returns:

  • (String)

    response body



853
854
855
# File 'lib/basecamp/http.rb', line 853

def body
  @body
end

#headersHash (readonly)

Returns response headers.

Returns:

  • (Hash)

    response headers



859
860
861
# File 'lib/basecamp/http.rb', line 859

def headers
  @headers
end

#statusInteger (readonly)

Returns HTTP status code.

Returns:

  • (Integer)

    HTTP status code



856
857
858
# File 'lib/basecamp/http.rb', line 856

def status
  @status
end

Instance Method Details

#jsonHash, Array

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

Returns:

  • (Hash, Array)


869
870
871
872
873
874
875
876
# File 'lib/basecamp/http.rb', line 869

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)


880
881
882
# File 'lib/basecamp/http.rb', line 880

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