Class: ElevenlabsClient::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/elevenlabs_client/client.rb

Overview

Main client class for the ElevenLabs API Refactored for better maintainability and architecture

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key: nil, base_url: nil, **options) ⇒ Client

Returns a new instance of Client.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/elevenlabs_client/client.rb', line 9

def initialize(api_key: nil, base_url: nil, **options)
  # Create configuration
  configuration = Configuration.new
  configuration.api_key = api_key if api_key
  configuration.base_url = base_url if base_url
  
  # Apply any additional options
  options.each do |key, value|
    configuration.public_send("#{key}=", value) if configuration.respond_to?("#{key}=")
  end

  # Validate configuration
  configuration.validate!

  # Create HTTP client
  @http_client = HttpClient.new(
    api_key: configuration.resolved_api_key,
    base_url: configuration.resolved_base_url
  )

  # Initialize endpoints directly for now (simpler approach)
  initialize_endpoints
end

Instance Attribute Details

#agentsObject (readonly)

Endpoint accessors



88
89
90
# File 'lib/elevenlabs_client/client.rb', line 88

def agents
  @agents
end

#audio_isolationObject (readonly)

Endpoint accessors



88
89
90
# File 'lib/elevenlabs_client/client.rb', line 88

def audio_isolation
  @audio_isolation
end

#audio_nativeObject (readonly)

Endpoint accessors



88
89
90
# File 'lib/elevenlabs_client/client.rb', line 88

def audio_native
  @audio_native
end

#batch_callingObject (readonly)

Endpoint accessors



88
89
90
# File 'lib/elevenlabs_client/client.rb', line 88

def batch_calling
  @batch_calling
end

#conversationsObject (readonly)

Endpoint accessors



88
89
90
# File 'lib/elevenlabs_client/client.rb', line 88

def conversations
  @conversations
end

#dubsObject (readonly)

Endpoint accessors



88
89
90
# File 'lib/elevenlabs_client/client.rb', line 88

def dubs
  @dubs
end

#forced_alignmentObject (readonly)

Endpoint accessors



88
89
90
# File 'lib/elevenlabs_client/client.rb', line 88

def forced_alignment
  @forced_alignment
end

#historyObject (readonly)

Endpoint accessors



88
89
90
# File 'lib/elevenlabs_client/client.rb', line 88

def history
  @history
end

#http_clientObject (readonly)

Returns the value of attribute http_client.



7
8
9
# File 'lib/elevenlabs_client/client.rb', line 7

def http_client
  @http_client
end

#knowledge_baseObject (readonly)

Endpoint accessors



88
89
90
# File 'lib/elevenlabs_client/client.rb', line 88

def knowledge_base
  @knowledge_base
end

#llm_usageObject (readonly)

Endpoint accessors



88
89
90
# File 'lib/elevenlabs_client/client.rb', line 88

def llm_usage
  @llm_usage
end

#mcp_serversObject (readonly)

Endpoint accessors



88
89
90
# File 'lib/elevenlabs_client/client.rb', line 88

def mcp_servers
  @mcp_servers
end

#modelsObject (readonly)

Endpoint accessors



88
89
90
# File 'lib/elevenlabs_client/client.rb', line 88

def models
  @models
end

#musicObject (readonly)

Endpoint accessors



88
89
90
# File 'lib/elevenlabs_client/client.rb', line 88

def music
  @music
end

#outbound_callingObject (readonly)

Endpoint accessors



88
89
90
# File 'lib/elevenlabs_client/client.rb', line 88

def outbound_calling
  @outbound_calling
end

#phone_numbersObject (readonly)

Endpoint accessors



88
89
90
# File 'lib/elevenlabs_client/client.rb', line 88

def phone_numbers
  @phone_numbers
end

#pronunciation_dictionariesObject (readonly)

Endpoint accessors



88
89
90
# File 'lib/elevenlabs_client/client.rb', line 88

def pronunciation_dictionaries
  @pronunciation_dictionaries
end

#samplesObject (readonly)

Endpoint accessors



88
89
90
# File 'lib/elevenlabs_client/client.rb', line 88

def samples
  @samples
end

#secretsObject (readonly)

Endpoint accessors



88
89
90
# File 'lib/elevenlabs_client/client.rb', line 88

def secrets
  @secrets
end

#service_account_api_keysObject (readonly)

Endpoint accessors



88
89
90
# File 'lib/elevenlabs_client/client.rb', line 88

def 
  @service_account_api_keys
end

#service_accountsObject (readonly)

Endpoint accessors



88
89
90
# File 'lib/elevenlabs_client/client.rb', line 88

def service_accounts
  @service_accounts
end

#sound_generationObject (readonly)

Endpoint accessors



88
89
90
# File 'lib/elevenlabs_client/client.rb', line 88

def sound_generation
  @sound_generation
end

#speech_to_speechObject (readonly)

Endpoint accessors



88
89
90
# File 'lib/elevenlabs_client/client.rb', line 88

def speech_to_speech
  @speech_to_speech
end

#speech_to_textObject (readonly)

Endpoint accessors



88
89
90
# File 'lib/elevenlabs_client/client.rb', line 88

def speech_to_text
  @speech_to_text
end

#test_invocationsObject (readonly)

Endpoint accessors



88
89
90
# File 'lib/elevenlabs_client/client.rb', line 88

def test_invocations
  @test_invocations
end

#testsObject (readonly)

Endpoint accessors



88
89
90
# File 'lib/elevenlabs_client/client.rb', line 88

def tests
  @tests
end

#text_to_dialogueObject (readonly)

Endpoint accessors



88
89
90
# File 'lib/elevenlabs_client/client.rb', line 88

def text_to_dialogue
  @text_to_dialogue
end

#text_to_speechObject (readonly)

Endpoint accessors



88
89
90
# File 'lib/elevenlabs_client/client.rb', line 88

def text_to_speech
  @text_to_speech
end

#text_to_voiceObject (readonly)

Endpoint accessors



88
89
90
# File 'lib/elevenlabs_client/client.rb', line 88

def text_to_voice
  @text_to_voice
end

#toolsObject (readonly)

Endpoint accessors



88
89
90
# File 'lib/elevenlabs_client/client.rb', line 88

def tools
  @tools
end

#usageObject (readonly)

Endpoint accessors



88
89
90
# File 'lib/elevenlabs_client/client.rb', line 88

def usage
  @usage
end

#userObject (readonly)

Endpoint accessors



88
89
90
# File 'lib/elevenlabs_client/client.rb', line 88

def user
  @user
end

#voice_libraryObject (readonly)

Endpoint accessors



88
89
90
# File 'lib/elevenlabs_client/client.rb', line 88

def voice_library
  @voice_library
end

#voicesObject (readonly)

Endpoint accessors



88
89
90
# File 'lib/elevenlabs_client/client.rb', line 88

def voices
  @voices
end

#webhooksObject (readonly)

Endpoint accessors



88
89
90
# File 'lib/elevenlabs_client/client.rb', line 88

def webhooks
  @webhooks
end

#websocket_text_to_speechObject (readonly)

Endpoint accessors



88
89
90
# File 'lib/elevenlabs_client/client.rb', line 88

def websocket_text_to_speech
  @websocket_text_to_speech
end

#widgetsObject (readonly)

Endpoint accessors



88
89
90
# File 'lib/elevenlabs_client/client.rb', line 88

def widgets
  @widgets
end

#workspaceObject (readonly)

Endpoint accessors



88
89
90
# File 'lib/elevenlabs_client/client.rb', line 88

def workspace
  @workspace
end

#workspace_groupsObject (readonly)

Endpoint accessors



88
89
90
# File 'lib/elevenlabs_client/client.rb', line 88

def workspace_groups
  @workspace_groups
end

#workspace_invitesObject (readonly)

Endpoint accessors



88
89
90
# File 'lib/elevenlabs_client/client.rb', line 88

def workspace_invites
  @workspace_invites
end

#workspace_membersObject (readonly)

Endpoint accessors



88
89
90
# File 'lib/elevenlabs_client/client.rb', line 88

def workspace_members
  @workspace_members
end

#workspace_resourcesObject (readonly)

Endpoint accessors



88
89
90
# File 'lib/elevenlabs_client/client.rb', line 88

def workspace_resources
  @workspace_resources
end

#workspace_webhooksObject (readonly)

Endpoint accessors



88
89
90
# File 'lib/elevenlabs_client/client.rb', line 88

def workspace_webhooks
  @workspace_webhooks
end

Instance Method Details

#api_keyObject



157
158
159
# File 'lib/elevenlabs_client/client.rb', line 157

def api_key
  http_client.api_key
end

#base_urlObject

Convenience accessors for backward compatibility



153
154
155
# File 'lib/elevenlabs_client/client.rb', line 153

def base_url
  http_client.base_url
end

#delete(path) ⇒ Object



112
113
114
# File 'lib/elevenlabs_client/client.rb', line 112

def delete(path)
  http_client.delete(path)
end

#delete_with_body(path, body = nil) ⇒ Object



116
117
118
# File 'lib/elevenlabs_client/client.rb', line 116

def delete_with_body(path, body = nil)
  http_client.delete_with_body(path, body)
end

#file_part(file_io, filename) ⇒ Object



148
149
150
# File 'lib/elevenlabs_client/client.rb', line 148

def file_part(file_io, filename)
  http_client.file_part(file_io, filename)
end

#get(path, params = {}) ⇒ Object

Delegate HTTP methods to http_client for backward compatibility



100
101
102
# File 'lib/elevenlabs_client/client.rb', line 100

def get(path, params = {})
  http_client.get(path, params)
end

#get_binary(path) ⇒ Object



124
125
126
# File 'lib/elevenlabs_client/client.rb', line 124

def get_binary(path)
  http_client.get_binary(path)
end

#get_streaming(path, &block) ⇒ Object



140
141
142
# File 'lib/elevenlabs_client/client.rb', line 140

def get_streaming(path, &block)
  http_client.get_streaming(path, &block)
end

#health_checkObject

Health check method



168
169
170
171
172
173
174
175
176
# File 'lib/elevenlabs_client/client.rb', line 168

def health_check
  begin
    # Try a simple API call to verify connectivity
    get("/v1/models")
    { status: :ok, message: "Client is healthy" }
  rescue => e
    { status: :error, message: e.message, error_class: e.class.name }
  end
end

#inspectObject

Debug information



162
163
164
165
# File 'lib/elevenlabs_client/client.rb', line 162

def inspect
  "#<#{self.class.name}:0x#{object_id.to_s(16)} " \
  "base_url=#{base_url.inspect}>"
end

#patch(path, body = nil) ⇒ Object



108
109
110
# File 'lib/elevenlabs_client/client.rb', line 108

def patch(path, body = nil)
  http_client.patch(path, body)
end

#post(path, body = nil) ⇒ Object



104
105
106
# File 'lib/elevenlabs_client/client.rb', line 104

def post(path, body = nil)
  http_client.post(path, body)
end

#post_binary(path, body = nil) ⇒ Object



128
129
130
# File 'lib/elevenlabs_client/client.rb', line 128

def post_binary(path, body = nil)
  http_client.post_binary(path, body)
end

#post_multipart(path, payload) ⇒ Object



120
121
122
# File 'lib/elevenlabs_client/client.rb', line 120

def post_multipart(path, payload)
  http_client.post_multipart(path, payload)
end

#post_streaming(path, body = nil, &block) ⇒ Object



136
137
138
# File 'lib/elevenlabs_client/client.rb', line 136

def post_streaming(path, body = nil, &block)
  http_client.post_streaming(path, body, &block)
end

#post_streaming_with_timestamps(path, body = nil, &block) ⇒ Object



144
145
146
# File 'lib/elevenlabs_client/client.rb', line 144

def post_streaming_with_timestamps(path, body = nil, &block)
  http_client.post_streaming_with_timestamps(path, body, &block)
end

#post_with_custom_headers(path, body = nil, custom_headers = {}) ⇒ Object



132
133
134
# File 'lib/elevenlabs_client/client.rb', line 132

def post_with_custom_headers(path, body = nil, custom_headers = {})
  http_client.post_with_custom_headers(path, body, custom_headers)
end