Class: Vapi::AsyncFilesClient

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_client:) ⇒ Vapi::AsyncFilesClient

Parameters:



180
181
182
# File 'lib/vapi_server_sdk/files/client.rb', line 180

def initialize(request_client:)
  @request_client = request_client
end

Instance Attribute Details

#request_clientVapi::AsyncRequestClient (readonly)



176
177
178
# File 'lib/vapi_server_sdk/files/client.rb', line 176

def request_client
  @request_client
end

Instance Method Details

#create(file:, request_options: nil) ⇒ Vapi::File

Examples:

api = Vapi::Client.new(
  base_url: "https://api.example.com",
  environment: Vapi::Environment::DEFAULT,
  token: "YOUR_AUTH_TOKEN"
)
api.files.create(file: my_file.txt)

Parameters:

Returns:



229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'lib/vapi_server_sdk/files/client.rb', line 229

def create(file:, request_options: nil)
  Async do
    response = @request_client.conn.post do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      req.headers["Authorization"] = request_options.token unless request_options&.token.nil?
      req.headers = {
    **(req.headers || {}),
    **@request_client.get_headers,
    **(request_options&.additional_headers || {})
      }.compact
      unless request_options.nil? || request_options&.additional_query_parameters.nil?
        req.params = { **(request_options&.additional_query_parameters || {}) }.compact
      end
      req.body = {
        **(request_options&.additional_body_parameters || {}),
        file: Vapi::FileUtilities.as_faraday_multipart(file_like: file)
      }.compact
      req.url "#{@request_client.get_url(request_options: request_options)}/file"
    end
    Vapi::File.from_json(json_object: response.body)
  end
end

#delete(id:, request_options: nil) ⇒ Vapi::File

Examples:

api = Vapi::Client.new(
  base_url: "https://api.example.com",
  environment: Vapi::Environment::DEFAULT,
  token: "YOUR_AUTH_TOKEN"
)
api.files.delete(id: "id")

Parameters:

Returns:



294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
# File 'lib/vapi_server_sdk/files/client.rb', line 294

def delete(id:, request_options: nil)
  Async do
    response = @request_client.conn.delete do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      req.headers["Authorization"] = request_options.token unless request_options&.token.nil?
      req.headers = {
    **(req.headers || {}),
    **@request_client.get_headers,
    **(request_options&.additional_headers || {})
      }.compact
      unless request_options.nil? || request_options&.additional_query_parameters.nil?
        req.params = { **(request_options&.additional_query_parameters || {}) }.compact
      end
      unless request_options.nil? || request_options&.additional_body_parameters.nil?
        req.body = { **(request_options&.additional_body_parameters || {}) }.compact
      end
      req.url "#{@request_client.get_url(request_options: request_options)}/file/#{id}"
    end
    Vapi::File.from_json(json_object: response.body)
  end
end

#get(id:, request_options: nil) ⇒ Vapi::File

Examples:

api = Vapi::Client.new(
  base_url: "https://api.example.com",
  environment: Vapi::Environment::DEFAULT,
  token: "YOUR_AUTH_TOKEN"
)
api.files.get(id: "id")

Parameters:

Returns:



262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/vapi_server_sdk/files/client.rb', line 262

def get(id:, request_options: nil)
  Async do
    response = @request_client.conn.get do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      req.headers["Authorization"] = request_options.token unless request_options&.token.nil?
      req.headers = {
    **(req.headers || {}),
    **@request_client.get_headers,
    **(request_options&.additional_headers || {})
      }.compact
      unless request_options.nil? || request_options&.additional_query_parameters.nil?
        req.params = { **(request_options&.additional_query_parameters || {}) }.compact
      end
      unless request_options.nil? || request_options&.additional_body_parameters.nil?
        req.body = { **(request_options&.additional_body_parameters || {}) }.compact
      end
      req.url "#{@request_client.get_url(request_options: request_options)}/file/#{id}"
    end
    Vapi::File.from_json(json_object: response.body)
  end
end

#list(request_options: nil) ⇒ Array<Vapi::File>

Examples:

api = Vapi::Client.new(
  base_url: "https://api.example.com",
  environment: Vapi::Environment::DEFAULT,
  token: "YOUR_AUTH_TOKEN"
)
api.files.list

Parameters:

Returns:



193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/vapi_server_sdk/files/client.rb', line 193

def list(request_options: nil)
  Async do
    response = @request_client.conn.get do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      req.headers["Authorization"] = request_options.token unless request_options&.token.nil?
      req.headers = {
    **(req.headers || {}),
    **@request_client.get_headers,
    **(request_options&.additional_headers || {})
      }.compact
      unless request_options.nil? || request_options&.additional_query_parameters.nil?
        req.params = { **(request_options&.additional_query_parameters || {}) }.compact
      end
      unless request_options.nil? || request_options&.additional_body_parameters.nil?
        req.body = { **(request_options&.additional_body_parameters || {}) }.compact
      end
      req.url "#{@request_client.get_url(request_options: request_options)}/file"
    end
    parsed_json = JSON.parse(response.body)
    parsed_json&.map do |item|
      item = item.to_json
      Vapi::File.from_json(json_object: item)
    end
  end
end

#update(id:, name: nil, request_options: nil) ⇒ Vapi::File

Examples:

api = Vapi::Client.new(
  base_url: "https://api.example.com",
  environment: Vapi::Environment::DEFAULT,
  token: "YOUR_AUTH_TOKEN"
)
api.files.update(id: "id")

Parameters:

  • id (String)
  • name (String) (defaults to: nil)

    This is the name of the file. This is just for your own reference.

  • request_options (Vapi::RequestOptions) (defaults to: nil)

Returns:



327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
# File 'lib/vapi_server_sdk/files/client.rb', line 327

def update(id:, name: nil, request_options: nil)
  Async do
    response = @request_client.conn.patch do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      req.headers["Authorization"] = request_options.token unless request_options&.token.nil?
      req.headers = {
    **(req.headers || {}),
    **@request_client.get_headers,
    **(request_options&.additional_headers || {})
      }.compact
      unless request_options.nil? || request_options&.additional_query_parameters.nil?
        req.params = { **(request_options&.additional_query_parameters || {}) }.compact
      end
      req.body = { **(request_options&.additional_body_parameters || {}), name: name }.compact
      req.url "#{@request_client.get_url(request_options: request_options)}/file/#{id}"
    end
    Vapi::File.from_json(json_object: response.body)
  end
end