Class: Openai::Client::Http
- Inherits:
-
Object
- Object
- Openai::Client::Http
- Defined in:
- lib/openai/client/http.rb
Instance Method Summary collapse
-
#delete(path) ⇒ Faraday::Response
Public: Makes a DELETE request using the Faraday HTTP Client.
-
#get(path, query_params = {}) ⇒ Faraday::Response
Public: Makes a GET request using the Faraday HTTP Client.
-
#initialize ⇒ Http
constructor
A new instance of Http.
-
#multipart_post(path, body = {}) ⇒ Faraday::Response
Public: Makes a multipart request using the Faraday HTTP Client.
-
#post(path, body = {}) ⇒ Faraday::Response
Public: Makes a POST request using the Faraday HTTP Client.
Constructor Details
#initialize ⇒ Http
Returns a new instance of Http.
6 7 8 9 10 11 12 13 14 |
# File 'lib/openai/client/http.rb', line 6 def initialize @connection = Faraday.new(url: Openai::Client.configuration.openai_url, headers: headers) do |conn| conn.response :json conn.response :raise_error conn.request :json conn.request :multipart end @logger = Openai::Client.configuration.logger end |
Instance Method Details
#delete(path) ⇒ Faraday::Response
Public: Makes a DELETE request using the Faraday HTTP Client.
72 73 74 75 76 |
# File 'lib/openai/client/http.rb', line 72 def delete(path) connection.delete(path) rescue Faraday::Error => e log_error(e) && raise end |
#get(path, query_params = {}) ⇒ Faraday::Response
Public: Makes a GET request using the Faraday HTTP Client.
25 26 27 28 29 |
# File 'lib/openai/client/http.rb', line 25 def get(path, query_params = {}) connection.get(path, query_params) rescue Faraday::Error => e log_error(e) && raise end |
#multipart_post(path, body = {}) ⇒ Faraday::Response
Public: Makes a multipart request using the Faraday HTTP Client.
55 56 57 58 59 60 61 62 |
# File 'lib/openai/client/http.rb', line 55 def multipart_post(path, body = {}) connection.post(path, body) do |request| request.headers['Content-Type'] = 'multipart/form-data' request..timeout = 300 end rescue Faraday::Error => e log_error(e) && raise end |
#post(path, body = {}) ⇒ Faraday::Response
Public: Makes a POST request using the Faraday HTTP Client.
40 41 42 43 44 |
# File 'lib/openai/client/http.rb', line 40 def post(path, body = {}) connection.post(path, body) rescue Faraday::Error => e log_error(e) && raise end |