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.



606
607
608
609
610
# File 'lib/basecamp/http.rb', line 606

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

Instance Attribute Details

#bodyString (readonly)

Returns response body.

Returns:

  • (String)

    response body



598
599
600
# File 'lib/basecamp/http.rb', line 598

def body
  @body
end

#headersHash (readonly)

Returns response headers.

Returns:

  • (Hash)

    response headers



604
605
606
# File 'lib/basecamp/http.rb', line 604

def headers
  @headers
end

#statusInteger (readonly)

Returns HTTP status code.

Returns:

  • (Integer)

    HTTP status code



601
602
603
# File 'lib/basecamp/http.rb', line 601

def status
  @status
end

Instance Method Details

#jsonHash, Array

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

Returns:

  • (Hash, Array)


614
615
616
617
618
619
620
621
# File 'lib/basecamp/http.rb', line 614

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)


625
626
627
# File 'lib/basecamp/http.rb', line 625

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