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