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