vapi_client/apis/
files_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
11use super::{configuration, ContentType, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{de::Error as _, Deserialize, Serialize};
15
16/// struct for typed errors of method [`file_controller_create`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum FileControllerCreateError {
20    Status400(),
21    UnknownValue(serde_json::Value),
22}
23
24/// struct for typed errors of method [`file_controller_find_all`]
25#[derive(Debug, Clone, Serialize, Deserialize)]
26#[serde(untagged)]
27pub enum FileControllerFindAllError {
28    UnknownValue(serde_json::Value),
29}
30
31/// struct for typed errors of method [`file_controller_find_one`]
32#[derive(Debug, Clone, Serialize, Deserialize)]
33#[serde(untagged)]
34pub enum FileControllerFindOneError {
35    UnknownValue(serde_json::Value),
36}
37
38/// struct for typed errors of method [`file_controller_remove`]
39#[derive(Debug, Clone, Serialize, Deserialize)]
40#[serde(untagged)]
41pub enum FileControllerRemoveError {
42    UnknownValue(serde_json::Value),
43}
44
45/// struct for typed errors of method [`file_controller_update`]
46#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum FileControllerUpdateError {
49    UnknownValue(serde_json::Value),
50}
51
52pub async fn file_controller_create(
53    configuration: &configuration::Configuration,
54    file: std::path::PathBuf,
55) -> Result<models::File, Error<FileControllerCreateError>> {
56    // add a prefix to parameters to efficiently prevent name collisions
57    let p_file = file;
58
59    let uri_str = format!("{}/file", configuration.base_path);
60    let mut req_builder = configuration
61        .client
62        .request(reqwest::Method::POST, &uri_str);
63
64    if let Some(ref user_agent) = configuration.user_agent {
65        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
66    }
67    if let Some(ref token) = configuration.bearer_access_token {
68        req_builder = req_builder.bearer_auth(token.to_owned());
69    };
70    let mut multipart_form = reqwest::multipart::Form::new();
71    // TODO: support file upload for 'file' parameter
72    req_builder = req_builder.multipart(multipart_form);
73
74    let req = req_builder.build()?;
75    let resp = configuration.client.execute(req).await?;
76
77    let status = resp.status();
78    let content_type = resp
79        .headers()
80        .get("content-type")
81        .and_then(|v| v.to_str().ok())
82        .unwrap_or("application/octet-stream");
83    let content_type = super::ContentType::from(content_type);
84
85    if !status.is_client_error() && !status.is_server_error() {
86        let content = resp.text().await?;
87        match content_type {
88            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
89            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::File`"))),
90            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::File`")))),
91        }
92    } else {
93        let content = resp.text().await?;
94        let entity: Option<FileControllerCreateError> = serde_json::from_str(&content).ok();
95        Err(Error::ResponseError(ResponseContent {
96            status,
97            content,
98            entity,
99        }))
100    }
101}
102
103pub async fn file_controller_find_all(
104    configuration: &configuration::Configuration,
105) -> Result<Vec<models::File>, Error<FileControllerFindAllError>> {
106    let uri_str = format!("{}/file", configuration.base_path);
107    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
108
109    if let Some(ref user_agent) = configuration.user_agent {
110        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
111    }
112    if let Some(ref token) = configuration.bearer_access_token {
113        req_builder = req_builder.bearer_auth(token.to_owned());
114    };
115
116    let req = req_builder.build()?;
117    let resp = configuration.client.execute(req).await?;
118
119    let status = resp.status();
120    let content_type = resp
121        .headers()
122        .get("content-type")
123        .and_then(|v| v.to_str().ok())
124        .unwrap_or("application/octet-stream");
125    let content_type = super::ContentType::from(content_type);
126
127    if !status.is_client_error() && !status.is_server_error() {
128        let content = resp.text().await?;
129        match content_type {
130            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
131            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::File&gt;`"))),
132            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::File&gt;`")))),
133        }
134    } else {
135        let content = resp.text().await?;
136        let entity: Option<FileControllerFindAllError> = serde_json::from_str(&content).ok();
137        Err(Error::ResponseError(ResponseContent {
138            status,
139            content,
140            entity,
141        }))
142    }
143}
144
145pub async fn file_controller_find_one(
146    configuration: &configuration::Configuration,
147    id: &str,
148) -> Result<models::File, Error<FileControllerFindOneError>> {
149    // add a prefix to parameters to efficiently prevent name collisions
150    let p_id = id;
151
152    let uri_str = format!(
153        "{}/file/{id}",
154        configuration.base_path,
155        id = crate::apis::urlencode(p_id)
156    );
157    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
158
159    if let Some(ref user_agent) = configuration.user_agent {
160        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
161    }
162    if let Some(ref token) = configuration.bearer_access_token {
163        req_builder = req_builder.bearer_auth(token.to_owned());
164    };
165
166    let req = req_builder.build()?;
167    let resp = configuration.client.execute(req).await?;
168
169    let status = resp.status();
170    let content_type = resp
171        .headers()
172        .get("content-type")
173        .and_then(|v| v.to_str().ok())
174        .unwrap_or("application/octet-stream");
175    let content_type = super::ContentType::from(content_type);
176
177    if !status.is_client_error() && !status.is_server_error() {
178        let content = resp.text().await?;
179        match content_type {
180            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
181            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::File`"))),
182            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::File`")))),
183        }
184    } else {
185        let content = resp.text().await?;
186        let entity: Option<FileControllerFindOneError> = serde_json::from_str(&content).ok();
187        Err(Error::ResponseError(ResponseContent {
188            status,
189            content,
190            entity,
191        }))
192    }
193}
194
195pub async fn file_controller_remove(
196    configuration: &configuration::Configuration,
197    id: &str,
198) -> Result<models::File, Error<FileControllerRemoveError>> {
199    // add a prefix to parameters to efficiently prevent name collisions
200    let p_id = id;
201
202    let uri_str = format!(
203        "{}/file/{id}",
204        configuration.base_path,
205        id = crate::apis::urlencode(p_id)
206    );
207    let mut req_builder = configuration
208        .client
209        .request(reqwest::Method::DELETE, &uri_str);
210
211    if let Some(ref user_agent) = configuration.user_agent {
212        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
213    }
214    if let Some(ref token) = configuration.bearer_access_token {
215        req_builder = req_builder.bearer_auth(token.to_owned());
216    };
217
218    let req = req_builder.build()?;
219    let resp = configuration.client.execute(req).await?;
220
221    let status = resp.status();
222    let content_type = resp
223        .headers()
224        .get("content-type")
225        .and_then(|v| v.to_str().ok())
226        .unwrap_or("application/octet-stream");
227    let content_type = super::ContentType::from(content_type);
228
229    if !status.is_client_error() && !status.is_server_error() {
230        let content = resp.text().await?;
231        match content_type {
232            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
233            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::File`"))),
234            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::File`")))),
235        }
236    } else {
237        let content = resp.text().await?;
238        let entity: Option<FileControllerRemoveError> = serde_json::from_str(&content).ok();
239        Err(Error::ResponseError(ResponseContent {
240            status,
241            content,
242            entity,
243        }))
244    }
245}
246
247pub async fn file_controller_update(
248    configuration: &configuration::Configuration,
249    id: &str,
250    update_file_dto: models::UpdateFileDto,
251) -> Result<models::File, Error<FileControllerUpdateError>> {
252    // add a prefix to parameters to efficiently prevent name collisions
253    let p_id = id;
254    let p_update_file_dto = update_file_dto;
255
256    let uri_str = format!(
257        "{}/file/{id}",
258        configuration.base_path,
259        id = crate::apis::urlencode(p_id)
260    );
261    let mut req_builder = configuration
262        .client
263        .request(reqwest::Method::PATCH, &uri_str);
264
265    if let Some(ref user_agent) = configuration.user_agent {
266        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
267    }
268    if let Some(ref token) = configuration.bearer_access_token {
269        req_builder = req_builder.bearer_auth(token.to_owned());
270    };
271    req_builder = req_builder.json(&p_update_file_dto);
272
273    let req = req_builder.build()?;
274    let resp = configuration.client.execute(req).await?;
275
276    let status = resp.status();
277    let content_type = resp
278        .headers()
279        .get("content-type")
280        .and_then(|v| v.to_str().ok())
281        .unwrap_or("application/octet-stream");
282    let content_type = super::ContentType::from(content_type);
283
284    if !status.is_client_error() && !status.is_server_error() {
285        let content = resp.text().await?;
286        match content_type {
287            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
288            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::File`"))),
289            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::File`")))),
290        }
291    } else {
292        let content = resp.text().await?;
293        let entity: Option<FileControllerUpdateError> = serde_json::from_str(&content).ok();
294        Err(Error::ResponseError(ResponseContent {
295            status,
296            content,
297            entity,
298        }))
299    }
300}