bitwarden_api_api/apis/
folders_api.rs

1/*
2 * Bitwarden Internal API
3 *
4 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5 *
6 * The version of the OpenAPI document: latest
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use reqwest;
12use serde::{de::Error as _, Deserialize, Serialize};
13
14use super::{configuration, ContentType, Error};
15use crate::{apis::ResponseContent, models};
16
17/// struct for typed errors of method [`folders_all_delete`]
18#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(untagged)]
20pub enum FoldersAllDeleteError {
21    UnknownValue(serde_json::Value),
22}
23
24/// struct for typed errors of method [`folders_get`]
25#[derive(Debug, Clone, Serialize, Deserialize)]
26#[serde(untagged)]
27pub enum FoldersGetError {
28    UnknownValue(serde_json::Value),
29}
30
31/// struct for typed errors of method [`folders_id_delete`]
32#[derive(Debug, Clone, Serialize, Deserialize)]
33#[serde(untagged)]
34pub enum FoldersIdDeleteError {
35    UnknownValue(serde_json::Value),
36}
37
38/// struct for typed errors of method [`folders_id_delete_post`]
39#[derive(Debug, Clone, Serialize, Deserialize)]
40#[serde(untagged)]
41pub enum FoldersIdDeletePostError {
42    UnknownValue(serde_json::Value),
43}
44
45/// struct for typed errors of method [`folders_id_get`]
46#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum FoldersIdGetError {
49    UnknownValue(serde_json::Value),
50}
51
52/// struct for typed errors of method [`folders_id_post`]
53#[derive(Debug, Clone, Serialize, Deserialize)]
54#[serde(untagged)]
55pub enum FoldersIdPostError {
56    UnknownValue(serde_json::Value),
57}
58
59/// struct for typed errors of method [`folders_id_put`]
60#[derive(Debug, Clone, Serialize, Deserialize)]
61#[serde(untagged)]
62pub enum FoldersIdPutError {
63    UnknownValue(serde_json::Value),
64}
65
66/// struct for typed errors of method [`folders_post`]
67#[derive(Debug, Clone, Serialize, Deserialize)]
68#[serde(untagged)]
69pub enum FoldersPostError {
70    UnknownValue(serde_json::Value),
71}
72
73pub async fn folders_all_delete(
74    configuration: &configuration::Configuration,
75) -> Result<(), Error<FoldersAllDeleteError>> {
76    let uri_str = format!("{}/folders/all", configuration.base_path);
77    let mut req_builder = configuration
78        .client
79        .request(reqwest::Method::DELETE, &uri_str);
80
81    if let Some(ref user_agent) = configuration.user_agent {
82        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
83    }
84    if let Some(ref token) = configuration.oauth_access_token {
85        req_builder = req_builder.bearer_auth(token.to_owned());
86    };
87
88    let req = req_builder.build()?;
89    let resp = configuration.client.execute(req).await?;
90
91    let status = resp.status();
92
93    if !status.is_client_error() && !status.is_server_error() {
94        Ok(())
95    } else {
96        let content = resp.text().await?;
97        let entity: Option<FoldersAllDeleteError> = serde_json::from_str(&content).ok();
98        Err(Error::ResponseError(ResponseContent {
99            status,
100            content,
101            entity,
102        }))
103    }
104}
105
106pub async fn folders_get(
107    configuration: &configuration::Configuration,
108) -> Result<models::FolderResponseModelListResponseModel, Error<FoldersGetError>> {
109    let uri_str = format!("{}/folders", configuration.base_path);
110    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
111
112    if let Some(ref user_agent) = configuration.user_agent {
113        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
114    }
115    if let Some(ref token) = configuration.oauth_access_token {
116        req_builder = req_builder.bearer_auth(token.to_owned());
117    };
118
119    let req = req_builder.build()?;
120    let resp = configuration.client.execute(req).await?;
121
122    let status = resp.status();
123    let content_type = resp
124        .headers()
125        .get("content-type")
126        .and_then(|v| v.to_str().ok())
127        .unwrap_or("application/octet-stream");
128    let content_type = super::ContentType::from(content_type);
129
130    if !status.is_client_error() && !status.is_server_error() {
131        let content = resp.text().await?;
132        match content_type {
133            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
134            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::FolderResponseModelListResponseModel`"))),
135            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::FolderResponseModelListResponseModel`")))),
136        }
137    } else {
138        let content = resp.text().await?;
139        let entity: Option<FoldersGetError> = serde_json::from_str(&content).ok();
140        Err(Error::ResponseError(ResponseContent {
141            status,
142            content,
143            entity,
144        }))
145    }
146}
147
148pub async fn folders_id_delete(
149    configuration: &configuration::Configuration,
150    id: &str,
151) -> Result<(), Error<FoldersIdDeleteError>> {
152    // add a prefix to parameters to efficiently prevent name collisions
153    let p_id = id;
154
155    let uri_str = format!(
156        "{}/folders/{id}",
157        configuration.base_path,
158        id = crate::apis::urlencode(p_id)
159    );
160    let mut req_builder = configuration
161        .client
162        .request(reqwest::Method::DELETE, &uri_str);
163
164    if let Some(ref user_agent) = configuration.user_agent {
165        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
166    }
167    if let Some(ref token) = configuration.oauth_access_token {
168        req_builder = req_builder.bearer_auth(token.to_owned());
169    };
170
171    let req = req_builder.build()?;
172    let resp = configuration.client.execute(req).await?;
173
174    let status = resp.status();
175
176    if !status.is_client_error() && !status.is_server_error() {
177        Ok(())
178    } else {
179        let content = resp.text().await?;
180        let entity: Option<FoldersIdDeleteError> = serde_json::from_str(&content).ok();
181        Err(Error::ResponseError(ResponseContent {
182            status,
183            content,
184            entity,
185        }))
186    }
187}
188
189pub async fn folders_id_delete_post(
190    configuration: &configuration::Configuration,
191    id: &str,
192) -> Result<(), Error<FoldersIdDeletePostError>> {
193    // add a prefix to parameters to efficiently prevent name collisions
194    let p_id = id;
195
196    let uri_str = format!(
197        "{}/folders/{id}/delete",
198        configuration.base_path,
199        id = crate::apis::urlencode(p_id)
200    );
201    let mut req_builder = configuration
202        .client
203        .request(reqwest::Method::POST, &uri_str);
204
205    if let Some(ref user_agent) = configuration.user_agent {
206        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
207    }
208    if let Some(ref token) = configuration.oauth_access_token {
209        req_builder = req_builder.bearer_auth(token.to_owned());
210    };
211
212    let req = req_builder.build()?;
213    let resp = configuration.client.execute(req).await?;
214
215    let status = resp.status();
216
217    if !status.is_client_error() && !status.is_server_error() {
218        Ok(())
219    } else {
220        let content = resp.text().await?;
221        let entity: Option<FoldersIdDeletePostError> = serde_json::from_str(&content).ok();
222        Err(Error::ResponseError(ResponseContent {
223            status,
224            content,
225            entity,
226        }))
227    }
228}
229
230pub async fn folders_id_get(
231    configuration: &configuration::Configuration,
232    id: &str,
233) -> Result<models::FolderResponseModel, Error<FoldersIdGetError>> {
234    // add a prefix to parameters to efficiently prevent name collisions
235    let p_id = id;
236
237    let uri_str = format!(
238        "{}/folders/{id}",
239        configuration.base_path,
240        id = crate::apis::urlencode(p_id)
241    );
242    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
243
244    if let Some(ref user_agent) = configuration.user_agent {
245        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
246    }
247    if let Some(ref token) = configuration.oauth_access_token {
248        req_builder = req_builder.bearer_auth(token.to_owned());
249    };
250
251    let req = req_builder.build()?;
252    let resp = configuration.client.execute(req).await?;
253
254    let status = resp.status();
255    let content_type = resp
256        .headers()
257        .get("content-type")
258        .and_then(|v| v.to_str().ok())
259        .unwrap_or("application/octet-stream");
260    let content_type = super::ContentType::from(content_type);
261
262    if !status.is_client_error() && !status.is_server_error() {
263        let content = resp.text().await?;
264        match content_type {
265            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
266            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::FolderResponseModel`"))),
267            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::FolderResponseModel`")))),
268        }
269    } else {
270        let content = resp.text().await?;
271        let entity: Option<FoldersIdGetError> = serde_json::from_str(&content).ok();
272        Err(Error::ResponseError(ResponseContent {
273            status,
274            content,
275            entity,
276        }))
277    }
278}
279
280pub async fn folders_id_post(
281    configuration: &configuration::Configuration,
282    id: &str,
283    folder_request_model: Option<models::FolderRequestModel>,
284) -> Result<models::FolderResponseModel, Error<FoldersIdPostError>> {
285    // add a prefix to parameters to efficiently prevent name collisions
286    let p_id = id;
287    let p_folder_request_model = folder_request_model;
288
289    let uri_str = format!(
290        "{}/folders/{id}",
291        configuration.base_path,
292        id = crate::apis::urlencode(p_id)
293    );
294    let mut req_builder = configuration
295        .client
296        .request(reqwest::Method::POST, &uri_str);
297
298    if let Some(ref user_agent) = configuration.user_agent {
299        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
300    }
301    if let Some(ref token) = configuration.oauth_access_token {
302        req_builder = req_builder.bearer_auth(token.to_owned());
303    };
304    req_builder = req_builder.json(&p_folder_request_model);
305
306    let req = req_builder.build()?;
307    let resp = configuration.client.execute(req).await?;
308
309    let status = resp.status();
310    let content_type = resp
311        .headers()
312        .get("content-type")
313        .and_then(|v| v.to_str().ok())
314        .unwrap_or("application/octet-stream");
315    let content_type = super::ContentType::from(content_type);
316
317    if !status.is_client_error() && !status.is_server_error() {
318        let content = resp.text().await?;
319        match content_type {
320            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
321            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::FolderResponseModel`"))),
322            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::FolderResponseModel`")))),
323        }
324    } else {
325        let content = resp.text().await?;
326        let entity: Option<FoldersIdPostError> = serde_json::from_str(&content).ok();
327        Err(Error::ResponseError(ResponseContent {
328            status,
329            content,
330            entity,
331        }))
332    }
333}
334
335pub async fn folders_id_put(
336    configuration: &configuration::Configuration,
337    id: &str,
338    folder_request_model: Option<models::FolderRequestModel>,
339) -> Result<models::FolderResponseModel, Error<FoldersIdPutError>> {
340    // add a prefix to parameters to efficiently prevent name collisions
341    let p_id = id;
342    let p_folder_request_model = folder_request_model;
343
344    let uri_str = format!(
345        "{}/folders/{id}",
346        configuration.base_path,
347        id = crate::apis::urlencode(p_id)
348    );
349    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
350
351    if let Some(ref user_agent) = configuration.user_agent {
352        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
353    }
354    if let Some(ref token) = configuration.oauth_access_token {
355        req_builder = req_builder.bearer_auth(token.to_owned());
356    };
357    req_builder = req_builder.json(&p_folder_request_model);
358
359    let req = req_builder.build()?;
360    let resp = configuration.client.execute(req).await?;
361
362    let status = resp.status();
363    let content_type = resp
364        .headers()
365        .get("content-type")
366        .and_then(|v| v.to_str().ok())
367        .unwrap_or("application/octet-stream");
368    let content_type = super::ContentType::from(content_type);
369
370    if !status.is_client_error() && !status.is_server_error() {
371        let content = resp.text().await?;
372        match content_type {
373            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
374            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::FolderResponseModel`"))),
375            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::FolderResponseModel`")))),
376        }
377    } else {
378        let content = resp.text().await?;
379        let entity: Option<FoldersIdPutError> = serde_json::from_str(&content).ok();
380        Err(Error::ResponseError(ResponseContent {
381            status,
382            content,
383            entity,
384        }))
385    }
386}
387
388pub async fn folders_post(
389    configuration: &configuration::Configuration,
390    folder_request_model: Option<models::FolderRequestModel>,
391) -> Result<models::FolderResponseModel, Error<FoldersPostError>> {
392    // add a prefix to parameters to efficiently prevent name collisions
393    let p_folder_request_model = folder_request_model;
394
395    let uri_str = format!("{}/folders", configuration.base_path);
396    let mut req_builder = configuration
397        .client
398        .request(reqwest::Method::POST, &uri_str);
399
400    if let Some(ref user_agent) = configuration.user_agent {
401        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
402    }
403    if let Some(ref token) = configuration.oauth_access_token {
404        req_builder = req_builder.bearer_auth(token.to_owned());
405    };
406    req_builder = req_builder.json(&p_folder_request_model);
407
408    let req = req_builder.build()?;
409    let resp = configuration.client.execute(req).await?;
410
411    let status = resp.status();
412    let content_type = resp
413        .headers()
414        .get("content-type")
415        .and_then(|v| v.to_str().ok())
416        .unwrap_or("application/octet-stream");
417    let content_type = super::ContentType::from(content_type);
418
419    if !status.is_client_error() && !status.is_server_error() {
420        let content = resp.text().await?;
421        match content_type {
422            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
423            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::FolderResponseModel`"))),
424            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::FolderResponseModel`")))),
425        }
426    } else {
427        let content = resp.text().await?;
428        let entity: Option<FoldersPostError> = serde_json::from_str(&content).ok();
429        Err(Error::ResponseError(ResponseContent {
430            status,
431            content,
432            entity,
433        }))
434    }
435}