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.
622 623 624 625 626 627 628 |
# File 'lib/tina4/api.rb', line 622 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.
618 619 620 |
# File 'lib/tina4/api.rb', line 618 def body @body end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
618 619 620 |
# File 'lib/tina4/api.rb', line 618 def error @error end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
618 619 620 |
# File 'lib/tina4/api.rb', line 618 def headers @headers end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
618 619 620 |
# File 'lib/tina4/api.rb', line 618 def path @path end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
618 619 620 |
# File 'lib/tina4/api.rb', line 618 def status @status end |
Instance Method Details
#json ⇒ Object
634 635 636 637 638 |
# File 'lib/tina4/api.rb', line 634 def json @json ||= JSON.parse(@body) rescue JSON::ParserError, TypeError {} end |
#success? ⇒ Boolean
630 631 632 |
# File 'lib/tina4/api.rb', line 630 def success? @status >= 200 && @status < 300 end |
#to_s ⇒ Object
640 641 642 |
# File 'lib/tina4/api.rb', line 640 def to_s "APIResponse(status=#{@status})" end |