Module: ElevenLabs::Connection

Included in:
Client
Defined in:
lib/eleven_labs/connection.rb

Overview

Network layer for API clients.

Constant Summary collapse

DEFAULT_MEDIA_TYPE =
"application/json"
USER_AGENT =
"ElevenLabs Ruby Gem"
CONVENIENCE_HEADERS =

Header keys that can be passed in options hash to #get,#head

Set.new(%i[accept content_type])

Instance Method Summary collapse

Instance Method Details

#agentSawyer::Agent

Hypermedia agent for the datatrans API

Returns:

  • (Sawyer::Agent)


74
75
76
77
78
79
80
81
82
83
# File 'lib/eleven_labs/connection.rb', line 74

def agent
  @agent ||= Faraday.new(url: endpoint) do |conn|
    conn.request :retry
    conn.headers['XI-API-KEY'] = api_key
    conn.headers["Content-Type"] = DEFAULT_MEDIA_TYPE
    conn.headers["Accept"] = DEFAULT_MEDIA_TYPE

    conn.adapter :net_http
  end
end

#delete(url, options = {}) ⇒ Sawyer::Resource

Make a HTTP DELETE request

Parameters:

Returns:

  • (Sawyer::Resource)


58
59
60
# File 'lib/eleven_labs/connection.rb', line 58

def delete(url, options = {})
  request :delete, url, options
end

#get(url, options = {}) ⇒ Sawyer::Resource

Make a HTTP GET request

Parameters:

Returns:

  • (Sawyer::Resource)


22
23
24
# File 'lib/eleven_labs/connection.rb', line 22

def get(url, options = {})
  request :get, url, options
end

#head(url, options = {}) ⇒ Sawyer::Resource

Make a HTTP HEAD request

Parameters:

Returns:

  • (Sawyer::Resource)


67
68
69
# File 'lib/eleven_labs/connection.rb', line 67

def head(url, options = {})
  request :head, url, options
end

#last_responseSawyer::Response

Response for last HTTP request

Returns:

  • (Sawyer::Response)


88
89
90
# File 'lib/eleven_labs/connection.rb', line 88

def last_response
  @last_response if defined? @last_response
end

#patch(url, options = {}) ⇒ Sawyer::Resource

Make a HTTP PATCH request

Parameters:

Returns:

  • (Sawyer::Resource)


49
50
51
# File 'lib/eleven_labs/connection.rb', line 49

def patch(url, options = {})
  request :patch, url, options.to_json
end

#post(url, options = {}) ⇒ Sawyer::Resource

Make a HTTP POST request

Parameters:

Returns:

  • (Sawyer::Resource)


31
32
33
# File 'lib/eleven_labs/connection.rb', line 31

def post(url, options = {})
  request :post, url, options.to_json
end

#put(url, options = {}) ⇒ Sawyer::Resource

Make a HTTP PUT request

Parameters:

Returns:

  • (Sawyer::Resource)


40
41
42
# File 'lib/eleven_labs/connection.rb', line 40

def put(url, options = {})
  request :put, url, options.to_json
end