Class: Rubygpt::Response::StandardApiResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/rubygpt/response.rb

Overview

Unifies responses from all connection/adapter objects.

This is required since a response from Faraday will not be the same as a response from another adapter
that might be introduced in the future. To solve this,
we're overriding the post, get, put, delete methods in connection objects to return a StandardApiResponse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status:, body:, headers:, adapter_response: nil) ⇒ StandardApiResponse

Returns a new instance of StandardApiResponse.

Parameters:

  • status (Integer)

    The HTTP status code

  • body (Hash)

    The response body

  • headers (Hash)

    The response headers

  • adapter_response (Object) (defaults to: nil)

    The original, non-standardized response object received from the adapter



23
24
25
26
27
28
# File 'lib/rubygpt/response.rb', line 23

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

Instance Attribute Details

#adapter_responseObject (readonly)

The original, non-standardized response object received from the adapter This is useful for debugging and for accessing adapter-specific features



17
18
19
# File 'lib/rubygpt/response.rb', line 17

def adapter_response
  @adapter_response
end

#bodyObject (readonly)

The HTTP package contents of the response



13
14
15
# File 'lib/rubygpt/response.rb', line 13

def body
  @body
end

#headersObject (readonly)

The HTTP package contents of the response



13
14
15
# File 'lib/rubygpt/response.rb', line 13

def headers
  @headers
end

#statusObject (readonly)

The HTTP package contents of the response



13
14
15
# File 'lib/rubygpt/response.rb', line 13

def status
  @status
end