Class: Tina4::APIResponse
- Inherits:
-
Object
- Object
- Tina4::APIResponse
- Defined in:
- lib/tina4/api.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#initialize(status:, body:, headers:, error: nil, path: nil) ⇒ APIResponse
constructor
path(default nil) is populated by API#download — the on-disk path the streamed body was written to (nil on error). - #json ⇒ Object
- #success? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(status:, body:, headers:, error: nil, path: nil) ⇒ APIResponse
path (default nil) is populated by API#download — the on-disk path the
streamed body was written to (nil on error). It is nil for every other verb.
617 618 619 620 621 622 623 |
# File 'lib/tina4/api.rb', line 617 def initialize(status:, body:, headers:, error: nil, path: nil) @status = status @body = body @headers = headers @error = error @path = path end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
613 614 615 |
# File 'lib/tina4/api.rb', line 613 def body @body end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
613 614 615 |
# File 'lib/tina4/api.rb', line 613 def error @error end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
613 614 615 |
# File 'lib/tina4/api.rb', line 613 def headers @headers end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
613 614 615 |
# File 'lib/tina4/api.rb', line 613 def path @path end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
613 614 615 |
# File 'lib/tina4/api.rb', line 613 def status @status end |
Instance Method Details
#json ⇒ Object
629 630 631 632 633 |
# File 'lib/tina4/api.rb', line 629 def json @json ||= JSON.parse(@body) rescue JSON::ParserError, TypeError {} end |
#success? ⇒ Boolean
625 626 627 |
# File 'lib/tina4/api.rb', line 625 def success? @status >= 200 && @status < 300 end |
#to_s ⇒ Object
635 636 637 |
# File 'lib/tina4/api.rb', line 635 def to_s "APIResponse(status=#{@status})" end |