vapi_client/apis/
calls_api.rs

1/*
2 * Vapi API
3 *
4 * Voice AI for developers.
5 *
6 * The version of the OpenAPI document: 1.0
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18/// struct for typed errors of method [`call_controller_create`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CallControllerCreateError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`call_controller_delete_call_data`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum CallControllerDeleteCallDataError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`call_controller_find_all`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum CallControllerFindAllError {
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method [`call_controller_find_one`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum CallControllerFindOneError {
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`call_controller_update`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum CallControllerUpdateError {
50    UnknownValue(serde_json::Value),
51}
52
53
54pub async fn call_controller_create(configuration: &configuration::Configuration, create_call_dto: models::CreateCallDto) -> Result<models::Call, Error<CallControllerCreateError>> {
55    // add a prefix to parameters to efficiently prevent name collisions
56    let p_create_call_dto = create_call_dto;
57
58    let uri_str = format!("{}/call", configuration.base_path);
59    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
60
61    if let Some(ref user_agent) = configuration.user_agent {
62        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
63    }
64    if let Some(ref token) = configuration.bearer_access_token {
65        req_builder = req_builder.bearer_auth(token.to_owned());
66    };
67    req_builder = req_builder.json(&p_create_call_dto);
68
69    let req = req_builder.build()?;
70    let resp = configuration.client.execute(req).await?;
71
72    let status = resp.status();
73    let content_type = resp
74        .headers()
75        .get("content-type")
76        .and_then(|v| v.to_str().ok())
77        .unwrap_or("application/octet-stream");
78    let content_type = super::ContentType::from(content_type);
79
80    if !status.is_client_error() && !status.is_server_error() {
81        let content = resp.text().await?;
82        match content_type {
83            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
84            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Call`"))),
85            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Call`")))),
86        }
87    } else {
88        let content = resp.text().await?;
89        let entity: Option<CallControllerCreateError> = serde_json::from_str(&content).ok();
90        Err(Error::ResponseError(ResponseContent { status, content, entity }))
91    }
92}
93
94pub async fn call_controller_delete_call_data(configuration: &configuration::Configuration, id: &str) -> Result<models::Call, Error<CallControllerDeleteCallDataError>> {
95    // add a prefix to parameters to efficiently prevent name collisions
96    let p_id = id;
97
98    let uri_str = format!("{}/call/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
99    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
100
101    if let Some(ref user_agent) = configuration.user_agent {
102        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
103    }
104    if let Some(ref token) = configuration.bearer_access_token {
105        req_builder = req_builder.bearer_auth(token.to_owned());
106    };
107
108    let req = req_builder.build()?;
109    let resp = configuration.client.execute(req).await?;
110
111    let status = resp.status();
112    let content_type = resp
113        .headers()
114        .get("content-type")
115        .and_then(|v| v.to_str().ok())
116        .unwrap_or("application/octet-stream");
117    let content_type = super::ContentType::from(content_type);
118
119    if !status.is_client_error() && !status.is_server_error() {
120        let content = resp.text().await?;
121        match content_type {
122            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
123            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Call`"))),
124            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Call`")))),
125        }
126    } else {
127        let content = resp.text().await?;
128        let entity: Option<CallControllerDeleteCallDataError> = serde_json::from_str(&content).ok();
129        Err(Error::ResponseError(ResponseContent { status, content, entity }))
130    }
131}
132
133pub async fn call_controller_find_all(configuration: &configuration::Configuration, id: Option<&str>, assistant_id: Option<&str>, phone_number_id: Option<&str>, limit: Option<f64>, created_at_gt: Option<String>, created_at_lt: Option<String>, created_at_ge: Option<String>, created_at_le: Option<String>, updated_at_gt: Option<String>, updated_at_lt: Option<String>, updated_at_ge: Option<String>, updated_at_le: Option<String>) -> Result<Vec<models::Call>, Error<CallControllerFindAllError>> {
134    // add a prefix to parameters to efficiently prevent name collisions
135    let p_id = id;
136    let p_assistant_id = assistant_id;
137    let p_phone_number_id = phone_number_id;
138    let p_limit = limit;
139    let p_created_at_gt = created_at_gt;
140    let p_created_at_lt = created_at_lt;
141    let p_created_at_ge = created_at_ge;
142    let p_created_at_le = created_at_le;
143    let p_updated_at_gt = updated_at_gt;
144    let p_updated_at_lt = updated_at_lt;
145    let p_updated_at_ge = updated_at_ge;
146    let p_updated_at_le = updated_at_le;
147
148    let uri_str = format!("{}/call", configuration.base_path);
149    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
150
151    if let Some(ref param_value) = p_id {
152        req_builder = req_builder.query(&[("id", &param_value.to_string())]);
153    }
154    if let Some(ref param_value) = p_assistant_id {
155        req_builder = req_builder.query(&[("assistantId", &param_value.to_string())]);
156    }
157    if let Some(ref param_value) = p_phone_number_id {
158        req_builder = req_builder.query(&[("phoneNumberId", &param_value.to_string())]);
159    }
160    if let Some(ref param_value) = p_limit {
161        req_builder = req_builder.query(&[("limit", &param_value.to_string())]);
162    }
163    if let Some(ref param_value) = p_created_at_gt {
164        req_builder = req_builder.query(&[("createdAtGt", &param_value.to_string())]);
165    }
166    if let Some(ref param_value) = p_created_at_lt {
167        req_builder = req_builder.query(&[("createdAtLt", &param_value.to_string())]);
168    }
169    if let Some(ref param_value) = p_created_at_ge {
170        req_builder = req_builder.query(&[("createdAtGe", &param_value.to_string())]);
171    }
172    if let Some(ref param_value) = p_created_at_le {
173        req_builder = req_builder.query(&[("createdAtLe", &param_value.to_string())]);
174    }
175    if let Some(ref param_value) = p_updated_at_gt {
176        req_builder = req_builder.query(&[("updatedAtGt", &param_value.to_string())]);
177    }
178    if let Some(ref param_value) = p_updated_at_lt {
179        req_builder = req_builder.query(&[("updatedAtLt", &param_value.to_string())]);
180    }
181    if let Some(ref param_value) = p_updated_at_ge {
182        req_builder = req_builder.query(&[("updatedAtGe", &param_value.to_string())]);
183    }
184    if let Some(ref param_value) = p_updated_at_le {
185        req_builder = req_builder.query(&[("updatedAtLe", &param_value.to_string())]);
186    }
187    if let Some(ref user_agent) = configuration.user_agent {
188        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
189    }
190    if let Some(ref token) = configuration.bearer_access_token {
191        req_builder = req_builder.bearer_auth(token.to_owned());
192    };
193
194    let req = req_builder.build()?;
195    let resp = configuration.client.execute(req).await?;
196
197    let status = resp.status();
198    let content_type = resp
199        .headers()
200        .get("content-type")
201        .and_then(|v| v.to_str().ok())
202        .unwrap_or("application/octet-stream");
203    let content_type = super::ContentType::from(content_type);
204
205    if !status.is_client_error() && !status.is_server_error() {
206        let content = resp.text().await?;
207        match content_type {
208            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
209            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::Call&gt;`"))),
210            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec&lt;models::Call&gt;`")))),
211        }
212    } else {
213        let content = resp.text().await?;
214        let entity: Option<CallControllerFindAllError> = serde_json::from_str(&content).ok();
215        Err(Error::ResponseError(ResponseContent { status, content, entity }))
216    }
217}
218
219pub async fn call_controller_find_one(configuration: &configuration::Configuration, id: &str) -> Result<models::Call, Error<CallControllerFindOneError>> {
220    // add a prefix to parameters to efficiently prevent name collisions
221    let p_id = id;
222
223    let uri_str = format!("{}/call/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
224    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
225
226    if let Some(ref user_agent) = configuration.user_agent {
227        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
228    }
229    if let Some(ref token) = configuration.bearer_access_token {
230        req_builder = req_builder.bearer_auth(token.to_owned());
231    };
232
233    let req = req_builder.build()?;
234    let resp = configuration.client.execute(req).await?;
235
236    let status = resp.status();
237    let content_type = resp
238        .headers()
239        .get("content-type")
240        .and_then(|v| v.to_str().ok())
241        .unwrap_or("application/octet-stream");
242    let content_type = super::ContentType::from(content_type);
243
244    if !status.is_client_error() && !status.is_server_error() {
245        let content = resp.text().await?;
246        match content_type {
247            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
248            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Call`"))),
249            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Call`")))),
250        }
251    } else {
252        let content = resp.text().await?;
253        let entity: Option<CallControllerFindOneError> = serde_json::from_str(&content).ok();
254        Err(Error::ResponseError(ResponseContent { status, content, entity }))
255    }
256}
257
258pub async fn call_controller_update(configuration: &configuration::Configuration, id: &str, update_call_dto: models::UpdateCallDto) -> Result<models::Call, Error<CallControllerUpdateError>> {
259    // add a prefix to parameters to efficiently prevent name collisions
260    let p_id = id;
261    let p_update_call_dto = update_call_dto;
262
263    let uri_str = format!("{}/call/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
264    let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
265
266    if let Some(ref user_agent) = configuration.user_agent {
267        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
268    }
269    if let Some(ref token) = configuration.bearer_access_token {
270        req_builder = req_builder.bearer_auth(token.to_owned());
271    };
272    req_builder = req_builder.json(&p_update_call_dto);
273
274    let req = req_builder.build()?;
275    let resp = configuration.client.execute(req).await?;
276
277    let status = resp.status();
278    let content_type = resp
279        .headers()
280        .get("content-type")
281        .and_then(|v| v.to_str().ok())
282        .unwrap_or("application/octet-stream");
283    let content_type = super::ContentType::from(content_type);
284
285    if !status.is_client_error() && !status.is_server_error() {
286        let content = resp.text().await?;
287        match content_type {
288            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
289            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Call`"))),
290            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Call`")))),
291        }
292    } else {
293        let content = resp.text().await?;
294        let entity: Option<CallControllerUpdateError> = serde_json::from_str(&content).ok();
295        Err(Error::ResponseError(ResponseContent { status, content, entity }))
296    }
297}
298