vapi_client/apis/
assistants_api.rs

1/*
2 * Vapi API
3 *
4 * API for building voice assistants
5 *
6 * The version of the OpenAPI document: 1.0
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use std::sync::Arc;
12
13use async_trait::async_trait;
14use reqwest;
15use serde::{de::Error as _, Deserialize, Serialize};
16
17use super::{configuration, Error};
18use crate::{
19    apis::{ContentType, ResponseContent},
20    models,
21};
22
23#[async_trait]
24pub trait AssistantsApi: Send + Sync {
25    /// POST /assistant
26    async fn assistant_controller_create<'create_assistant_dto>(
27        &self,
28        create_assistant_dto: models::CreateAssistantDto,
29    ) -> Result<models::Assistant, Error<AssistantControllerCreateError>>;
30
31    /// GET /assistant
32    async fn assistant_controller_find_all<
33        'limit,
34        'created_at_gt,
35        'created_at_lt,
36        'created_at_ge,
37        'created_at_le,
38        'updated_at_gt,
39        'updated_at_lt,
40        'updated_at_ge,
41        'updated_at_le,
42    >(
43        &self,
44        limit: Option<f64>,
45        created_at_gt: Option<String>,
46        created_at_lt: Option<String>,
47        created_at_ge: Option<String>,
48        created_at_le: Option<String>,
49        updated_at_gt: Option<String>,
50        updated_at_lt: Option<String>,
51        updated_at_ge: Option<String>,
52        updated_at_le: Option<String>,
53    ) -> Result<Vec<models::Assistant>, Error<AssistantControllerFindAllError>>;
54
55    /// GET /assistant/{id}
56    async fn assistant_controller_find_one<'id>(
57        &self,
58        id: &'id str,
59    ) -> Result<models::Assistant, Error<AssistantControllerFindOneError>>;
60
61    /// DELETE /assistant/{id}
62    async fn assistant_controller_remove<'id>(
63        &self,
64        id: &'id str,
65    ) -> Result<models::Assistant, Error<AssistantControllerRemoveError>>;
66
67    /// PATCH /assistant/{id}
68    async fn assistant_controller_update<'id, 'update_assistant_dto>(
69        &self,
70        id: &'id str,
71        update_assistant_dto: models::UpdateAssistantDto,
72    ) -> Result<models::Assistant, Error<AssistantControllerUpdateError>>;
73}
74
75pub struct AssistantsApiClient {
76    configuration: Arc<configuration::Configuration>,
77}
78
79impl AssistantsApiClient {
80    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
81        Self { configuration }
82    }
83}
84
85#[async_trait]
86impl AssistantsApi for AssistantsApiClient {
87    async fn assistant_controller_create<'create_assistant_dto>(
88        &self,
89        create_assistant_dto: models::CreateAssistantDto,
90    ) -> Result<models::Assistant, Error<AssistantControllerCreateError>> {
91        let local_var_configuration = &self.configuration;
92
93        let local_var_client = &local_var_configuration.client;
94
95        let local_var_uri_str = format!("{}/assistant", local_var_configuration.base_path);
96        let mut local_var_req_builder =
97            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
98
99        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
100            local_var_req_builder = local_var_req_builder
101                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
102        }
103        if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
104            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
105        };
106        local_var_req_builder = local_var_req_builder.json(&create_assistant_dto);
107
108        let local_var_req = local_var_req_builder.build()?;
109        let local_var_resp = local_var_client.execute(local_var_req).await?;
110
111        let local_var_status = local_var_resp.status();
112        let local_var_content_type = local_var_resp
113            .headers()
114            .get("content-type")
115            .and_then(|v| v.to_str().ok())
116            .unwrap_or("application/octet-stream");
117        let local_var_content_type = super::ContentType::from(local_var_content_type);
118        let local_var_content = local_var_resp.text().await?;
119
120        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
121            match local_var_content_type {
122                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
123                ContentType::Text => {
124                    return Err(Error::from(serde_json::Error::custom(
125                        "Received `text/plain` content type response that cannot be converted to \
126                         `models::Assistant`",
127                    )))
128                }
129                ContentType::Unsupported(local_var_unknown_type) => {
130                    return Err(Error::from(serde_json::Error::custom(format!(
131                        "Received `{local_var_unknown_type}` content type response that cannot be \
132                         converted to `models::Assistant`"
133                    ))))
134                }
135            }
136        } else {
137            let local_var_entity: Option<AssistantControllerCreateError> =
138                serde_json::from_str(&local_var_content).ok();
139            let local_var_error = ResponseContent {
140                status: local_var_status,
141                content: local_var_content,
142                entity: local_var_entity,
143            };
144            Err(Error::ResponseError(local_var_error))
145        }
146    }
147
148    async fn assistant_controller_find_all<
149        'limit,
150        'created_at_gt,
151        'created_at_lt,
152        'created_at_ge,
153        'created_at_le,
154        'updated_at_gt,
155        'updated_at_lt,
156        'updated_at_ge,
157        'updated_at_le,
158    >(
159        &self,
160        limit: Option<f64>,
161        created_at_gt: Option<String>,
162        created_at_lt: Option<String>,
163        created_at_ge: Option<String>,
164        created_at_le: Option<String>,
165        updated_at_gt: Option<String>,
166        updated_at_lt: Option<String>,
167        updated_at_ge: Option<String>,
168        updated_at_le: Option<String>,
169    ) -> Result<Vec<models::Assistant>, Error<AssistantControllerFindAllError>> {
170        let local_var_configuration = &self.configuration;
171
172        let local_var_client = &local_var_configuration.client;
173
174        let local_var_uri_str = format!("{}/assistant", local_var_configuration.base_path);
175        let mut local_var_req_builder =
176            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
177
178        if let Some(ref local_var_str) = limit {
179            local_var_req_builder =
180                local_var_req_builder.query(&[("limit", &local_var_str.to_string())]);
181        }
182        if let Some(ref local_var_str) = created_at_gt {
183            local_var_req_builder =
184                local_var_req_builder.query(&[("createdAtGt", &local_var_str.to_string())]);
185        }
186        if let Some(ref local_var_str) = created_at_lt {
187            local_var_req_builder =
188                local_var_req_builder.query(&[("createdAtLt", &local_var_str.to_string())]);
189        }
190        if let Some(ref local_var_str) = created_at_ge {
191            local_var_req_builder =
192                local_var_req_builder.query(&[("createdAtGe", &local_var_str.to_string())]);
193        }
194        if let Some(ref local_var_str) = created_at_le {
195            local_var_req_builder =
196                local_var_req_builder.query(&[("createdAtLe", &local_var_str.to_string())]);
197        }
198        if let Some(ref local_var_str) = updated_at_gt {
199            local_var_req_builder =
200                local_var_req_builder.query(&[("updatedAtGt", &local_var_str.to_string())]);
201        }
202        if let Some(ref local_var_str) = updated_at_lt {
203            local_var_req_builder =
204                local_var_req_builder.query(&[("updatedAtLt", &local_var_str.to_string())]);
205        }
206        if let Some(ref local_var_str) = updated_at_ge {
207            local_var_req_builder =
208                local_var_req_builder.query(&[("updatedAtGe", &local_var_str.to_string())]);
209        }
210        if let Some(ref local_var_str) = updated_at_le {
211            local_var_req_builder =
212                local_var_req_builder.query(&[("updatedAtLe", &local_var_str.to_string())]);
213        }
214        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
215            local_var_req_builder = local_var_req_builder
216                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
217        }
218        if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
219            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
220        };
221
222        let local_var_req = local_var_req_builder.build()?;
223        let local_var_resp = local_var_client.execute(local_var_req).await?;
224
225        let local_var_status = local_var_resp.status();
226        let local_var_content_type = local_var_resp
227            .headers()
228            .get("content-type")
229            .and_then(|v| v.to_str().ok())
230            .unwrap_or("application/octet-stream");
231        let local_var_content_type = super::ContentType::from(local_var_content_type);
232        let local_var_content = local_var_resp.text().await?;
233
234        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
235            match local_var_content_type {
236                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
237                ContentType::Text => {
238                    return Err(Error::from(serde_json::Error::custom(
239                        "Received `text/plain` content type response that cannot be converted to \
240                         `Vec&lt;models::Assistant&gt;`",
241                    )))
242                }
243                ContentType::Unsupported(local_var_unknown_type) => {
244                    return Err(Error::from(serde_json::Error::custom(format!(
245                        "Received `{local_var_unknown_type}` content type response that cannot be \
246                         converted to `Vec&lt;models::Assistant&gt;`"
247                    ))))
248                }
249            }
250        } else {
251            let local_var_entity: Option<AssistantControllerFindAllError> =
252                serde_json::from_str(&local_var_content).ok();
253            let local_var_error = ResponseContent {
254                status: local_var_status,
255                content: local_var_content,
256                entity: local_var_entity,
257            };
258            Err(Error::ResponseError(local_var_error))
259        }
260    }
261
262    async fn assistant_controller_find_one<'id>(
263        &self,
264        id: &'id str,
265    ) -> Result<models::Assistant, Error<AssistantControllerFindOneError>> {
266        let local_var_configuration = &self.configuration;
267
268        let local_var_client = &local_var_configuration.client;
269
270        let local_var_uri_str = format!(
271            "{}/assistant/{id}",
272            local_var_configuration.base_path,
273            id = crate::apis::urlencode(id)
274        );
275        let mut local_var_req_builder =
276            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
277
278        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
279            local_var_req_builder = local_var_req_builder
280                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
281        }
282        if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
283            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
284        };
285
286        let local_var_req = local_var_req_builder.build()?;
287        let local_var_resp = local_var_client.execute(local_var_req).await?;
288
289        let local_var_status = local_var_resp.status();
290        let local_var_content_type = local_var_resp
291            .headers()
292            .get("content-type")
293            .and_then(|v| v.to_str().ok())
294            .unwrap_or("application/octet-stream");
295        let local_var_content_type = super::ContentType::from(local_var_content_type);
296        let local_var_content = local_var_resp.text().await?;
297
298        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
299            match local_var_content_type {
300                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
301                ContentType::Text => {
302                    return Err(Error::from(serde_json::Error::custom(
303                        "Received `text/plain` content type response that cannot be converted to \
304                         `models::Assistant`",
305                    )))
306                }
307                ContentType::Unsupported(local_var_unknown_type) => {
308                    return Err(Error::from(serde_json::Error::custom(format!(
309                        "Received `{local_var_unknown_type}` content type response that cannot be \
310                         converted to `models::Assistant`"
311                    ))))
312                }
313            }
314        } else {
315            let local_var_entity: Option<AssistantControllerFindOneError> =
316                serde_json::from_str(&local_var_content).ok();
317            let local_var_error = ResponseContent {
318                status: local_var_status,
319                content: local_var_content,
320                entity: local_var_entity,
321            };
322            Err(Error::ResponseError(local_var_error))
323        }
324    }
325
326    async fn assistant_controller_remove<'id>(
327        &self,
328        id: &'id str,
329    ) -> Result<models::Assistant, Error<AssistantControllerRemoveError>> {
330        let local_var_configuration = &self.configuration;
331
332        let local_var_client = &local_var_configuration.client;
333
334        let local_var_uri_str = format!(
335            "{}/assistant/{id}",
336            local_var_configuration.base_path,
337            id = crate::apis::urlencode(id)
338        );
339        let mut local_var_req_builder =
340            local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
341
342        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
343            local_var_req_builder = local_var_req_builder
344                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
345        }
346        if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
347            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
348        };
349
350        let local_var_req = local_var_req_builder.build()?;
351        let local_var_resp = local_var_client.execute(local_var_req).await?;
352
353        let local_var_status = local_var_resp.status();
354        let local_var_content_type = local_var_resp
355            .headers()
356            .get("content-type")
357            .and_then(|v| v.to_str().ok())
358            .unwrap_or("application/octet-stream");
359        let local_var_content_type = super::ContentType::from(local_var_content_type);
360        let local_var_content = local_var_resp.text().await?;
361
362        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
363            match local_var_content_type {
364                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
365                ContentType::Text => {
366                    return Err(Error::from(serde_json::Error::custom(
367                        "Received `text/plain` content type response that cannot be converted to \
368                         `models::Assistant`",
369                    )))
370                }
371                ContentType::Unsupported(local_var_unknown_type) => {
372                    return Err(Error::from(serde_json::Error::custom(format!(
373                        "Received `{local_var_unknown_type}` content type response that cannot be \
374                         converted to `models::Assistant`"
375                    ))))
376                }
377            }
378        } else {
379            let local_var_entity: Option<AssistantControllerRemoveError> =
380                serde_json::from_str(&local_var_content).ok();
381            let local_var_error = ResponseContent {
382                status: local_var_status,
383                content: local_var_content,
384                entity: local_var_entity,
385            };
386            Err(Error::ResponseError(local_var_error))
387        }
388    }
389
390    async fn assistant_controller_update<'id, 'update_assistant_dto>(
391        &self,
392        id: &'id str,
393        update_assistant_dto: models::UpdateAssistantDto,
394    ) -> Result<models::Assistant, Error<AssistantControllerUpdateError>> {
395        let local_var_configuration = &self.configuration;
396
397        let local_var_client = &local_var_configuration.client;
398
399        let local_var_uri_str = format!(
400            "{}/assistant/{id}",
401            local_var_configuration.base_path,
402            id = crate::apis::urlencode(id)
403        );
404        let mut local_var_req_builder =
405            local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
406
407        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
408            local_var_req_builder = local_var_req_builder
409                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
410        }
411        if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
412            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
413        };
414        local_var_req_builder = local_var_req_builder.json(&update_assistant_dto);
415
416        let local_var_req = local_var_req_builder.build()?;
417        let local_var_resp = local_var_client.execute(local_var_req).await?;
418
419        let local_var_status = local_var_resp.status();
420        let local_var_content_type = local_var_resp
421            .headers()
422            .get("content-type")
423            .and_then(|v| v.to_str().ok())
424            .unwrap_or("application/octet-stream");
425        let local_var_content_type = super::ContentType::from(local_var_content_type);
426        let local_var_content = local_var_resp.text().await?;
427
428        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
429            match local_var_content_type {
430                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
431                ContentType::Text => {
432                    return Err(Error::from(serde_json::Error::custom(
433                        "Received `text/plain` content type response that cannot be converted to \
434                         `models::Assistant`",
435                    )))
436                }
437                ContentType::Unsupported(local_var_unknown_type) => {
438                    return Err(Error::from(serde_json::Error::custom(format!(
439                        "Received `{local_var_unknown_type}` content type response that cannot be \
440                         converted to `models::Assistant`"
441                    ))))
442                }
443            }
444        } else {
445            let local_var_entity: Option<AssistantControllerUpdateError> =
446                serde_json::from_str(&local_var_content).ok();
447            let local_var_error = ResponseContent {
448                status: local_var_status,
449                content: local_var_content,
450                entity: local_var_entity,
451            };
452            Err(Error::ResponseError(local_var_error))
453        }
454    }
455}
456
457/// struct for typed errors of method [`assistant_controller_create`]
458#[derive(Debug, Clone, Serialize, Deserialize)]
459#[serde(untagged)]
460pub enum AssistantControllerCreateError {
461    UnknownValue(serde_json::Value),
462}
463
464/// struct for typed errors of method [`assistant_controller_find_all`]
465#[derive(Debug, Clone, Serialize, Deserialize)]
466#[serde(untagged)]
467pub enum AssistantControllerFindAllError {
468    UnknownValue(serde_json::Value),
469}
470
471/// struct for typed errors of method [`assistant_controller_find_one`]
472#[derive(Debug, Clone, Serialize, Deserialize)]
473#[serde(untagged)]
474pub enum AssistantControllerFindOneError {
475    UnknownValue(serde_json::Value),
476}
477
478/// struct for typed errors of method [`assistant_controller_remove`]
479#[derive(Debug, Clone, Serialize, Deserialize)]
480#[serde(untagged)]
481pub enum AssistantControllerRemoveError {
482    UnknownValue(serde_json::Value),
483}
484
485/// struct for typed errors of method [`assistant_controller_update`]
486#[derive(Debug, Clone, Serialize, Deserialize)]
487#[serde(untagged)]
488pub enum AssistantControllerUpdateError {
489    UnknownValue(serde_json::Value),
490}