Class: Basecamp::Response
- Inherits:
-
Object
- Object
- Basecamp::Response
- Defined in:
- lib/basecamp/http.rb
Overview
Wraps an HTTP response.
Instance Attribute Summary collapse
-
#body ⇒ String
readonly
Response body.
-
#headers ⇒ Hash
readonly
Response headers.
-
#status ⇒ Integer
readonly
HTTP status code.
Instance Method Summary collapse
-
#initialize(body:, status:, headers:) ⇒ Response
constructor
A new instance of Response.
-
#json ⇒ Hash, Array
Parses the response body as JSON, normalizing Person-shaped objects.
-
#success? ⇒ Boolean
Returns whether the response was successful (2xx).
Constructor Details
#initialize(body:, status:, headers:) ⇒ Response
Returns a new instance of Response.
635 636 637 638 639 |
# File 'lib/basecamp/http.rb', line 635 def initialize(body:, status:, headers:) @body = body @status = status @headers = headers end |
Instance Attribute Details
#body ⇒ String (readonly)
Returns response body.
627 628 629 |
# File 'lib/basecamp/http.rb', line 627 def body @body end |
#headers ⇒ Hash (readonly)
Returns response headers.
633 634 635 |
# File 'lib/basecamp/http.rb', line 633 def headers @headers end |
#status ⇒ Integer (readonly)
Returns HTTP status code.
630 631 632 |
# File 'lib/basecamp/http.rb', line 630 def status @status end |
Instance Method Details
#json ⇒ Hash, Array
Parses the response body as JSON, normalizing Person-shaped objects.
643 644 645 646 647 648 649 650 |
# File 'lib/basecamp/http.rb', line 643 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).
654 655 656 |
# File 'lib/basecamp/http.rb', line 654 def success? status >= 200 && status < 300 end |