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