Class: Tina4::APIResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/tina4/api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status:, body:, headers:, error: nil) ⇒ APIResponse

Returns a new instance of APIResponse.



230
231
232
233
234
235
# File 'lib/tina4/api.rb', line 230

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

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



228
229
230
# File 'lib/tina4/api.rb', line 228

def body
  @body
end

#errorObject (readonly)

Returns the value of attribute error.



228
229
230
# File 'lib/tina4/api.rb', line 228

def error
  @error
end

#headersObject (readonly)

Returns the value of attribute headers.



228
229
230
# File 'lib/tina4/api.rb', line 228

def headers
  @headers
end

#statusObject (readonly)

Returns the value of attribute status.



228
229
230
# File 'lib/tina4/api.rb', line 228

def status
  @status
end

Instance Method Details

#jsonObject



241
242
243
244
245
# File 'lib/tina4/api.rb', line 241

def json
  @json ||= JSON.parse(@body)
rescue JSON::ParserError
  {}
end

#success?Boolean

Returns:

  • (Boolean)


237
238
239
# File 'lib/tina4/api.rb', line 237

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

#to_sObject



247
248
249
# File 'lib/tina4/api.rb', line 247

def to_s
  "APIResponse(status=#{@status})"
end