Class: Rubygpt::Connection::Faraday

Inherits:
Faraday::Connection
  • Object
show all
Defined in:
lib/rubygpt/connection/faraday.rb

Overview

The HTTP connection adapter derived from Faraday::Connection

Instance Method Summary collapse

Constructor Details

#initialize(configuration, faraday_options = {}) ⇒ Faraday

Initializes a new connection object

Parameters:

  • configuration (Configuration)
  • faraday_options (Hash) (defaults to: {})


13
14
15
16
17
18
19
20
# File 'lib/rubygpt/connection/faraday.rb', line 13

def initialize(configuration, faraday_options = {})
  options = { url: configuration.api_url, headers: configuration.to_headers }.merge(faraday_options)
  super(options) do |faraday|
    faraday.request :json
    faraday.response :json
    faraday.response :raise_error
  end
end

Instance Method Details

#post(*args) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/rubygpt/connection/faraday.rb', line 22

def post(*args)
  faraday_response = super(*args)
  Rubygpt::Response::StandardApiResponse.new(
    adapter_response: faraday_response,
    status: faraday_response.status,
    body: faraday_response.body,
    headers: faraday_response.headers
  )
end