Skip to main content

bitwarden_api_api/apis/
sends_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 std::sync::Arc;
12
13use async_trait::async_trait;
14#[cfg(feature = "mockall")]
15use mockall::automock;
16use reqwest;
17use serde::{Deserialize, Serialize, de::Error as _};
18
19use super::{Error, configuration};
20use crate::{
21    apis::{AuthRequired, ContentType, ResponseContent},
22    models,
23};
24
25#[cfg_attr(feature = "mockall", automock)]
26#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
27#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
28pub trait SendsApi: Send + Sync {
29    /// POST /sends/access
30    async fn access_using_auth<'a>(
31        &self,
32        access_token: &'a str,
33    ) -> Result<models::SendAccessResponseModel, Error>;
34
35    /// POST /sends/file/validate/azure
36    async fn azure_validate_file(&self) -> Result<(), Error>;
37
38    /// DELETE /sends/{id}
39    async fn delete<'a>(&self, id: &'a str) -> Result<(), Error>;
40
41    /// GET /sends/{id}
42    async fn get<'a>(&self, id: &'a str) -> Result<models::SendResponseModel, Error>;
43
44    /// GET /sends
45    async fn get_all(&self) -> Result<models::SendResponseModelListResponseModel, Error>;
46
47    /// POST /sends/access/file/{fileId}
48    async fn get_send_file_download_data_using_auth<'a>(
49        &self,
50        file_id: &'a str,
51        access_token: &'a str,
52    ) -> Result<models::SendFileDownloadDataResponseModel, Error>;
53
54    /// POST /sends
55    async fn post<'a>(
56        &self,
57        send_request_model: Option<models::SendRequestModel>,
58    ) -> Result<models::SendResponseModel, Error>;
59
60    /// POST /sends/file/v2
61    async fn post_file<'a>(
62        &self,
63        send_request_model: Option<models::SendRequestModel>,
64    ) -> Result<models::SendFileUploadDataResponseModel, Error>;
65
66    /// POST /sends/{id}/file/{fileId}
67    async fn post_file_for_existing_send<'a>(
68        &self,
69        id: &'a str,
70        file_id: &'a str,
71        data: std::path::PathBuf,
72    ) -> Result<(), Error>;
73
74    /// PUT /sends/{id}
75    async fn put<'a>(
76        &self,
77        id: &'a str,
78        send_request_model: Option<models::SendRequestModel>,
79    ) -> Result<models::SendResponseModel, Error>;
80
81    /// PUT /sends/{id}/remove-auth
82    async fn put_remove_auth<'a>(&self, id: &'a str) -> Result<models::SendResponseModel, Error>;
83
84    /// PUT /sends/{id}/remove-password
85    async fn put_remove_password<'a>(
86        &self,
87        id: &'a str,
88    ) -> Result<models::SendResponseModel, Error>;
89
90    /// GET /sends/{id}/file/{fileId}
91    async fn renew_file_upload<'a>(
92        &self,
93        id: &'a str,
94        file_id: &'a str,
95    ) -> Result<models::SendFileUploadDataResponseModel, Error>;
96}
97
98pub struct SendsApiClient {
99    configuration: Arc<configuration::Configuration>,
100}
101
102impl SendsApiClient {
103    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
104        Self { configuration }
105    }
106}
107
108#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
109#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
110impl SendsApi for SendsApiClient {
111    async fn access_using_auth<'a>(
112        &self,
113        access_token: &'a str,
114    ) -> Result<models::SendAccessResponseModel, Error> {
115        let local_var_configuration = &self.configuration;
116
117        let local_var_client = &local_var_configuration.client;
118
119        let local_var_uri_str = format!("{}/sends/access", local_var_configuration.base_path);
120        let mut local_var_req_builder =
121            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
122
123        local_var_req_builder = local_var_req_builder.header(
124            reqwest::header::AUTHORIZATION,
125            format!("Bearer {}", access_token),
126        );
127
128        bitwarden_api_base::process_with_json_response(local_var_req_builder).await
129    }
130
131    async fn azure_validate_file(&self) -> Result<(), Error> {
132        let local_var_configuration = &self.configuration;
133
134        let local_var_client = &local_var_configuration.client;
135
136        let local_var_uri_str = format!(
137            "{}/sends/file/validate/azure",
138            local_var_configuration.base_path
139        );
140        let mut local_var_req_builder =
141            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
142
143        bitwarden_api_base::process_with_empty_response(local_var_req_builder).await
144    }
145
146    async fn delete<'a>(&self, id: &'a str) -> Result<(), Error> {
147        let local_var_configuration = &self.configuration;
148
149        let local_var_client = &local_var_configuration.client;
150
151        let local_var_uri_str = format!(
152            "{}/sends/{id}",
153            local_var_configuration.base_path,
154            id = crate::apis::urlencode(id)
155        );
156        let mut local_var_req_builder =
157            local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
158
159        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
160
161        bitwarden_api_base::process_with_empty_response(local_var_req_builder).await
162    }
163
164    async fn get<'a>(&self, id: &'a str) -> Result<models::SendResponseModel, Error> {
165        let local_var_configuration = &self.configuration;
166
167        let local_var_client = &local_var_configuration.client;
168
169        let local_var_uri_str = format!(
170            "{}/sends/{id}",
171            local_var_configuration.base_path,
172            id = crate::apis::urlencode(id)
173        );
174        let mut local_var_req_builder =
175            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
176
177        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
178
179        bitwarden_api_base::process_with_json_response(local_var_req_builder).await
180    }
181
182    async fn get_all(&self) -> Result<models::SendResponseModelListResponseModel, Error> {
183        let local_var_configuration = &self.configuration;
184
185        let local_var_client = &local_var_configuration.client;
186
187        let local_var_uri_str = format!("{}/sends", local_var_configuration.base_path);
188        let mut local_var_req_builder =
189            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
190
191        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
192
193        bitwarden_api_base::process_with_json_response(local_var_req_builder).await
194    }
195
196    async fn get_send_file_download_data_using_auth<'a>(
197        &self,
198        file_id: &'a str,
199        access_token: &'a str,
200    ) -> Result<models::SendFileDownloadDataResponseModel, Error> {
201        let local_var_configuration = &self.configuration;
202
203        let local_var_client = &local_var_configuration.client;
204
205        let local_var_uri_str = format!(
206            "{}/sends/access/file/{fileId}",
207            local_var_configuration.base_path,
208            fileId = crate::apis::urlencode(file_id)
209        );
210        let mut local_var_req_builder =
211            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
212
213        local_var_req_builder = local_var_req_builder.header(
214            reqwest::header::AUTHORIZATION,
215            format!("Bearer {}", access_token),
216        );
217
218        bitwarden_api_base::process_with_json_response(local_var_req_builder).await
219    }
220
221    async fn post<'a>(
222        &self,
223        send_request_model: Option<models::SendRequestModel>,
224    ) -> Result<models::SendResponseModel, Error> {
225        let local_var_configuration = &self.configuration;
226
227        let local_var_client = &local_var_configuration.client;
228
229        let local_var_uri_str = format!("{}/sends", local_var_configuration.base_path);
230        let mut local_var_req_builder =
231            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
232
233        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
234        local_var_req_builder = local_var_req_builder.json(&send_request_model);
235
236        bitwarden_api_base::process_with_json_response(local_var_req_builder).await
237    }
238
239    async fn post_file<'a>(
240        &self,
241        send_request_model: Option<models::SendRequestModel>,
242    ) -> Result<models::SendFileUploadDataResponseModel, Error> {
243        let local_var_configuration = &self.configuration;
244
245        let local_var_client = &local_var_configuration.client;
246
247        let local_var_uri_str = format!("{}/sends/file/v2", local_var_configuration.base_path);
248        let mut local_var_req_builder =
249            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
250
251        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
252        local_var_req_builder = local_var_req_builder.json(&send_request_model);
253
254        bitwarden_api_base::process_with_json_response(local_var_req_builder).await
255    }
256
257    async fn post_file_for_existing_send<'a>(
258        &self,
259        id: &'a str,
260        file_id: &'a str,
261        data: std::path::PathBuf,
262    ) -> Result<(), Error> {
263        let local_var_configuration = &self.configuration;
264
265        let local_var_client = &local_var_configuration.client;
266
267        let local_var_uri_str = format!(
268            "{}/sends/{id}/file/{fileId}",
269            local_var_configuration.base_path,
270            id = crate::apis::urlencode(id),
271            fileId = crate::apis::urlencode(file_id)
272        );
273        let mut local_var_req_builder =
274            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
275
276        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
277        let mut local_var_form = reqwest::multipart::Form::new();
278        // TODO: support file upload for 'data' parameter
279        local_var_req_builder = local_var_req_builder.multipart(local_var_form);
280
281        bitwarden_api_base::process_with_empty_response(local_var_req_builder).await
282    }
283
284    async fn put<'a>(
285        &self,
286        id: &'a str,
287        send_request_model: Option<models::SendRequestModel>,
288    ) -> Result<models::SendResponseModel, Error> {
289        let local_var_configuration = &self.configuration;
290
291        let local_var_client = &local_var_configuration.client;
292
293        let local_var_uri_str = format!(
294            "{}/sends/{id}",
295            local_var_configuration.base_path,
296            id = crate::apis::urlencode(id)
297        );
298        let mut local_var_req_builder =
299            local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
300
301        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
302        local_var_req_builder = local_var_req_builder.json(&send_request_model);
303
304        bitwarden_api_base::process_with_json_response(local_var_req_builder).await
305    }
306
307    async fn put_remove_auth<'a>(&self, id: &'a str) -> Result<models::SendResponseModel, Error> {
308        let local_var_configuration = &self.configuration;
309
310        let local_var_client = &local_var_configuration.client;
311
312        let local_var_uri_str = format!(
313            "{}/sends/{id}/remove-auth",
314            local_var_configuration.base_path,
315            id = crate::apis::urlencode(id)
316        );
317        let mut local_var_req_builder =
318            local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
319
320        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
321
322        bitwarden_api_base::process_with_json_response(local_var_req_builder).await
323    }
324
325    async fn put_remove_password<'a>(
326        &self,
327        id: &'a str,
328    ) -> Result<models::SendResponseModel, Error> {
329        let local_var_configuration = &self.configuration;
330
331        let local_var_client = &local_var_configuration.client;
332
333        let local_var_uri_str = format!(
334            "{}/sends/{id}/remove-password",
335            local_var_configuration.base_path,
336            id = crate::apis::urlencode(id)
337        );
338        let mut local_var_req_builder =
339            local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
340
341        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
342
343        bitwarden_api_base::process_with_json_response(local_var_req_builder).await
344    }
345
346    async fn renew_file_upload<'a>(
347        &self,
348        id: &'a str,
349        file_id: &'a str,
350    ) -> Result<models::SendFileUploadDataResponseModel, Error> {
351        let local_var_configuration = &self.configuration;
352
353        let local_var_client = &local_var_configuration.client;
354
355        let local_var_uri_str = format!(
356            "{}/sends/{id}/file/{fileId}",
357            local_var_configuration.base_path,
358            id = crate::apis::urlencode(id),
359            fileId = crate::apis::urlencode(file_id)
360        );
361        let mut local_var_req_builder =
362            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
363
364        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
365
366        bitwarden_api_base::process_with_json_response(local_var_req_builder).await
367    }
368}