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.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#initialize(status:, body:, headers:, error: nil) ⇒ APIResponse
constructor
A new instance of APIResponse.
- #json ⇒ Object
- #success? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(status:, body:, headers:, error: nil) ⇒ APIResponse
Returns a new instance of APIResponse.
168 169 170 171 172 173 |
# File 'lib/tina4/api.rb', line 168 def initialize(status:, body:, headers:, error: nil) @status = status @body = body @headers = headers @error = error end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
166 167 168 |
# File 'lib/tina4/api.rb', line 166 def body @body end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
166 167 168 |
# File 'lib/tina4/api.rb', line 166 def error @error end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
166 167 168 |
# File 'lib/tina4/api.rb', line 166 def headers @headers end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
166 167 168 |
# File 'lib/tina4/api.rb', line 166 def status @status end |
Instance Method Details
#json ⇒ Object
179 180 181 182 183 |
# File 'lib/tina4/api.rb', line 179 def json @json ||= JSON.parse(@body) rescue JSON::ParserError {} end |
#success? ⇒ Boolean
175 176 177 |
# File 'lib/tina4/api.rb', line 175 def success? @status >= 200 && @status < 300 end |
#to_s ⇒ Object
185 186 187 |
# File 'lib/tina4/api.rb', line 185 def to_s "APIResponse(status=#{@status})" end |