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, 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

#bodyObject (readonly)

Returns the value of attribute body.



613
614
615
# File 'lib/tina4/api.rb', line 613

def body
  @body
end

#errorObject (readonly)

Returns the value of attribute error.



613
614
615
# File 'lib/tina4/api.rb', line 613

def error
  @error
end

#headersObject (readonly)

Returns the value of attribute headers.



613
614
615
# File 'lib/tina4/api.rb', line 613

def headers
  @headers
end

#pathObject (readonly)

Returns the value of attribute path.



613
614
615
# File 'lib/tina4/api.rb', line 613

def path
  @path
end

#statusObject (readonly)

Returns the value of attribute status.



613
614
615
# File 'lib/tina4/api.rb', line 613

def status
  @status
end

Instance Method Details

#jsonObject



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

Returns:

  • (Boolean)


625
626
627
# File 'lib/tina4/api.rb', line 625

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

#to_sObject



635
636
637
# File 'lib/tina4/api.rb', line 635

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