Class: Vapi::AsyncFilesClient
- Inherits:
-
Object
- Object
- Vapi::AsyncFilesClient
- Defined in:
- lib/vapi_server_sdk/files/client.rb
Instance Attribute Summary collapse
Instance Method Summary collapse
- #create(file:, request_options: nil) ⇒ Vapi::File
- #delete(id:, request_options: nil) ⇒ Vapi::File
- #get(id:, request_options: nil) ⇒ Vapi::File
- #initialize(request_client:) ⇒ Vapi::AsyncFilesClient constructor
- #list(request_options: nil) ⇒ Array<Vapi::File>
- #update(id:, name: nil, request_options: nil) ⇒ Vapi::File
Constructor Details
#initialize(request_client:) ⇒ Vapi::AsyncFilesClient
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_client ⇒ Vapi::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
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..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? req.headers["Authorization"] = .token unless &.token.nil? req.headers = { **(req.headers || {}), **@request_client.get_headers, **(&.additional_headers || {}) }.compact unless .nil? || &.additional_query_parameters.nil? req.params = { **(&.additional_query_parameters || {}) }.compact end req.body = { **(&.additional_body_parameters || {}), file: Vapi::FileUtilities.as_faraday_multipart(file_like: file) }.compact req.url "#{@request_client.get_url(request_options: )}/file" end Vapi::File.from_json(json_object: response.body) end end |
#delete(id:, request_options: nil) ⇒ Vapi::File
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..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? req.headers["Authorization"] = .token unless &.token.nil? req.headers = { **(req.headers || {}), **@request_client.get_headers, **(&.additional_headers || {}) }.compact unless .nil? || &.additional_query_parameters.nil? req.params = { **(&.additional_query_parameters || {}) }.compact end unless .nil? || &.additional_body_parameters.nil? req.body = { **(&.additional_body_parameters || {}) }.compact end req.url "#{@request_client.get_url(request_options: )}/file/#{id}" end Vapi::File.from_json(json_object: response.body) end end |
#get(id:, request_options: nil) ⇒ Vapi::File
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..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? req.headers["Authorization"] = .token unless &.token.nil? req.headers = { **(req.headers || {}), **@request_client.get_headers, **(&.additional_headers || {}) }.compact unless .nil? || &.additional_query_parameters.nil? req.params = { **(&.additional_query_parameters || {}) }.compact end unless .nil? || &.additional_body_parameters.nil? req.body = { **(&.additional_body_parameters || {}) }.compact end req.url "#{@request_client.get_url(request_options: )}/file/#{id}" end Vapi::File.from_json(json_object: response.body) end end |
#list(request_options: nil) ⇒ Array<Vapi::File>
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..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? req.headers["Authorization"] = .token unless &.token.nil? req.headers = { **(req.headers || {}), **@request_client.get_headers, **(&.additional_headers || {}) }.compact unless .nil? || &.additional_query_parameters.nil? req.params = { **(&.additional_query_parameters || {}) }.compact end unless .nil? || &.additional_body_parameters.nil? req.body = { **(&.additional_body_parameters || {}) }.compact end req.url "#{@request_client.get_url(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
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..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? req.headers["Authorization"] = .token unless &.token.nil? req.headers = { **(req.headers || {}), **@request_client.get_headers, **(&.additional_headers || {}) }.compact unless .nil? || &.additional_query_parameters.nil? req.params = { **(&.additional_query_parameters || {}) }.compact end req.body = { **(&.additional_body_parameters || {}), name: name }.compact req.url "#{@request_client.get_url(request_options: )}/file/#{id}" end Vapi::File.from_json(json_object: response.body) end end |