Class: Retell::SDK::Unofficial::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/retell/sdk/unofficial/client.rb

Constant Summary collapse

DEFAULT_BASE_URL =
'https://api.retellai.com'.freeze
DEFAULT_TIMEOUT =
60

Instance Method Summary collapse

Constructor Details

#initialize(api_key:, base_url: nil, timeout: DEFAULT_TIMEOUT) ⇒ Client

Returns a new instance of Client.



18
19
20
21
22
# File 'lib/retell/sdk/unofficial/client.rb', line 18

def initialize(api_key:, base_url: nil, timeout: DEFAULT_TIMEOUT)
  @api_key = api_key
  @base_url = base_url || DEFAULT_BASE_URL
  @timeout = timeout
end

Instance Method Details

#agentObject



24
25
26
# File 'lib/retell/sdk/unofficial/client.rb', line 24

def agent
  @agent ||= Retell::SDK::Unofficial::API::Agent.new(self)
end

#agentsObject



48
49
50
# File 'lib/retell/sdk/unofficial/client.rb', line 48

def agents
  agent.list
end

#callObject



28
29
30
# File 'lib/retell/sdk/unofficial/client.rb', line 28

def call
  @call ||= Retell::SDK::Unofficial::API::Call.new(self)
end

#calls(**params) ⇒ Object



52
53
54
# File 'lib/retell/sdk/unofficial/client.rb', line 52

def calls(**params)
  call.list(**params)
end

#concurrencyObject



44
45
46
# File 'lib/retell/sdk/unofficial/client.rb', line 44

def concurrency
  @concurrency ||= Retell::SDK::Unofficial::API::Concurrency.new(self)
end

#delete(path, params = {}, **options) ⇒ Object



118
119
120
121
# File 'lib/retell/sdk/unofficial/client.rb', line 118

def delete(path, params = {}, **options)
  request(:delete, path, params, **options)
  nil
end

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



106
107
108
# File 'lib/retell/sdk/unofficial/client.rb', line 106

def get(path, params = {}, **options)
  request(:get, path, params, **options)
end

#make_request_options(extra_headers: nil, extra_query: nil, extra_body: nil, timeout: nil) ⇒ Object



123
124
125
126
127
128
129
130
# File 'lib/retell/sdk/unofficial/client.rb', line 123

def make_request_options(extra_headers: nil, extra_query: nil, extra_body: nil, timeout: nil)
  options = {}
  options[:headers] = extra_headers || {}
  options[:query] = extra_query || {}
  options[:body] = extra_body || {}
  options[:timeout] = timeout if timeout
  options
end

#patch(path, params = {}, **options) ⇒ Object



114
115
116
# File 'lib/retell/sdk/unofficial/client.rb', line 114

def patch(path, params = {}, **options)
  request(:patch, path, params, **options)
end

#phone_numberObject



36
37
38
# File 'lib/retell/sdk/unofficial/client.rb', line 36

def phone_number
  @phone_number ||= Retell::SDK::Unofficial::API::PhoneNumber.new(self)
end

#phone_numbersObject



60
61
62
# File 'lib/retell/sdk/unofficial/client.rb', line 60

def phone_numbers
  phone_number.list
end

#post(path, params = {}, **options) ⇒ Object



110
111
112
# File 'lib/retell/sdk/unofficial/client.rb', line 110

def post(path, params = {}, **options)
  request(:post, path, params, **options)
end

#request(method, path, params = {}, **options) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/retell/sdk/unofficial/client.rb', line 68

def request(method, path, params = {}, **options)
  url = "#{@base_url}#{path}"

  http_options = {
    headers: headers.merge(options[:headers] || {}),
    format: :json,
    timeout: options[:timeout] || @timeout
  }

  body_params = options[:body] || {}

  if [:get, :delete].include?(method)
    options[:query] = options[:query].merge(params)
  else
    options[:body] = options[:body].merge(params)
  end

  http_options[:query] = options[:query] unless options[:query].empty?

  if [:post, :patch].include?(method)
    http_options[:body] = options[:body].to_json
  elsif !body_params.empty?
    http_options[:body] = body_params.to_json
  end

  begin
    response = HTTParty.send(
      method,
      url,
      http_options
    )
  rescue Net::OpenTimeout, Net::ReadTimeout, Timeout::Error, Errno::ETIMEDOUT => e
    raise APITimeoutError.new(http_options)
  end

  handle_response(response)
end

#retell_llmObject



32
33
34
# File 'lib/retell/sdk/unofficial/client.rb', line 32

def retell_llm
  @retell_llm ||= Retell::SDK::Unofficial::API::RetellLLM.new(self)
end

#retell_llmsObject



56
57
58
# File 'lib/retell/sdk/unofficial/client.rb', line 56

def retell_llms
  retell_llm.list
end

#voiceObject



40
41
42
# File 'lib/retell/sdk/unofficial/client.rb', line 40

def voice
  @voice ||= Retell::SDK::Unofficial::API::Voice.new(self)
end

#voicesObject



64
65
66
# File 'lib/retell/sdk/unofficial/client.rb', line 64

def voices
  voice.list
end