1use 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::{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 FoldersApi: Send + Sync {
29 async fn delete<'a>(&self, id: &'a str) -> Result<(), Error<DeleteError>>;
31
32 async fn delete_all(&self) -> Result<(), Error<DeleteAllError>>;
34
35 async fn get<'a>(&self, id: &'a str) -> Result<models::FolderResponseModel, Error<GetError>>;
37
38 async fn get_all(
40 &self,
41 ) -> Result<models::FolderResponseModelListResponseModel, Error<GetAllError>>;
42
43 async fn post<'a>(
45 &self,
46 folder_request_model: Option<models::FolderRequestModel>,
47 ) -> Result<models::FolderResponseModel, Error<PostError>>;
48
49 async fn put<'a>(
51 &self,
52 id: &'a str,
53 folder_request_model: Option<models::FolderRequestModel>,
54 ) -> Result<models::FolderResponseModel, Error<PutError>>;
55}
56
57pub struct FoldersApiClient {
58 configuration: Arc<configuration::Configuration>,
59}
60
61impl FoldersApiClient {
62 pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
63 Self { configuration }
64 }
65}
66
67#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
68#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
69impl FoldersApi for FoldersApiClient {
70 async fn delete<'a>(&self, id: &'a str) -> Result<(), Error<DeleteError>> {
71 let local_var_configuration = &self.configuration;
72
73 let local_var_client = &local_var_configuration.client;
74
75 let local_var_uri_str = format!(
76 "{}/folders/{id}",
77 local_var_configuration.base_path,
78 id = crate::apis::urlencode(id)
79 );
80 let mut local_var_req_builder =
81 local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
82
83 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
84 local_var_req_builder = local_var_req_builder
85 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
86 }
87 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
88 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
89 };
90
91 let local_var_req = local_var_req_builder.build()?;
92 let local_var_resp = local_var_client.execute(local_var_req).await?;
93
94 let local_var_status = local_var_resp.status();
95 let local_var_content = local_var_resp.text().await?;
96
97 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
98 Ok(())
99 } else {
100 let local_var_entity: Option<DeleteError> =
101 serde_json::from_str(&local_var_content).ok();
102 let local_var_error = ResponseContent {
103 status: local_var_status,
104 content: local_var_content,
105 entity: local_var_entity,
106 };
107 Err(Error::ResponseError(local_var_error))
108 }
109 }
110
111 async fn delete_all(&self) -> Result<(), Error<DeleteAllError>> {
112 let local_var_configuration = &self.configuration;
113
114 let local_var_client = &local_var_configuration.client;
115
116 let local_var_uri_str = format!("{}/folders/all", local_var_configuration.base_path);
117 let mut local_var_req_builder =
118 local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
119
120 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
121 local_var_req_builder = local_var_req_builder
122 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
123 }
124 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
125 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
126 };
127
128 let local_var_req = local_var_req_builder.build()?;
129 let local_var_resp = local_var_client.execute(local_var_req).await?;
130
131 let local_var_status = local_var_resp.status();
132 let local_var_content = local_var_resp.text().await?;
133
134 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
135 Ok(())
136 } else {
137 let local_var_entity: Option<DeleteAllError> =
138 serde_json::from_str(&local_var_content).ok();
139 let local_var_error = ResponseContent {
140 status: local_var_status,
141 content: local_var_content,
142 entity: local_var_entity,
143 };
144 Err(Error::ResponseError(local_var_error))
145 }
146 }
147
148 async fn get<'a>(&self, id: &'a str) -> Result<models::FolderResponseModel, Error<GetError>> {
149 let local_var_configuration = &self.configuration;
150
151 let local_var_client = &local_var_configuration.client;
152
153 let local_var_uri_str = format!(
154 "{}/folders/{id}",
155 local_var_configuration.base_path,
156 id = crate::apis::urlencode(id)
157 );
158 let mut local_var_req_builder =
159 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
160
161 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
162 local_var_req_builder = local_var_req_builder
163 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
164 }
165 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
166 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
167 };
168
169 let local_var_req = local_var_req_builder.build()?;
170 let local_var_resp = local_var_client.execute(local_var_req).await?;
171
172 let local_var_status = local_var_resp.status();
173 let local_var_content_type = local_var_resp
174 .headers()
175 .get("content-type")
176 .and_then(|v| v.to_str().ok())
177 .unwrap_or("application/octet-stream");
178 let local_var_content_type = super::ContentType::from(local_var_content_type);
179 let local_var_content = local_var_resp.text().await?;
180
181 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
182 match local_var_content_type {
183 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
184 ContentType::Text => {
185 return Err(Error::from(serde_json::Error::custom(
186 "Received `text/plain` content type response that cannot be converted to `models::FolderResponseModel`",
187 )));
188 }
189 ContentType::Unsupported(local_var_unknown_type) => {
190 return Err(Error::from(serde_json::Error::custom(format!(
191 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::FolderResponseModel`"
192 ))));
193 }
194 }
195 } else {
196 let local_var_entity: Option<GetError> = serde_json::from_str(&local_var_content).ok();
197 let local_var_error = ResponseContent {
198 status: local_var_status,
199 content: local_var_content,
200 entity: local_var_entity,
201 };
202 Err(Error::ResponseError(local_var_error))
203 }
204 }
205
206 async fn get_all(
207 &self,
208 ) -> Result<models::FolderResponseModelListResponseModel, Error<GetAllError>> {
209 let local_var_configuration = &self.configuration;
210
211 let local_var_client = &local_var_configuration.client;
212
213 let local_var_uri_str = format!("{}/folders", local_var_configuration.base_path);
214 let mut local_var_req_builder =
215 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
216
217 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
218 local_var_req_builder = local_var_req_builder
219 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
220 }
221 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
222 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
223 };
224
225 let local_var_req = local_var_req_builder.build()?;
226 let local_var_resp = local_var_client.execute(local_var_req).await?;
227
228 let local_var_status = local_var_resp.status();
229 let local_var_content_type = local_var_resp
230 .headers()
231 .get("content-type")
232 .and_then(|v| v.to_str().ok())
233 .unwrap_or("application/octet-stream");
234 let local_var_content_type = super::ContentType::from(local_var_content_type);
235 let local_var_content = local_var_resp.text().await?;
236
237 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
238 match local_var_content_type {
239 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
240 ContentType::Text => {
241 return Err(Error::from(serde_json::Error::custom(
242 "Received `text/plain` content type response that cannot be converted to `models::FolderResponseModelListResponseModel`",
243 )));
244 }
245 ContentType::Unsupported(local_var_unknown_type) => {
246 return Err(Error::from(serde_json::Error::custom(format!(
247 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::FolderResponseModelListResponseModel`"
248 ))));
249 }
250 }
251 } else {
252 let local_var_entity: Option<GetAllError> =
253 serde_json::from_str(&local_var_content).ok();
254 let local_var_error = ResponseContent {
255 status: local_var_status,
256 content: local_var_content,
257 entity: local_var_entity,
258 };
259 Err(Error::ResponseError(local_var_error))
260 }
261 }
262
263 async fn post<'a>(
264 &self,
265 folder_request_model: Option<models::FolderRequestModel>,
266 ) -> Result<models::FolderResponseModel, Error<PostError>> {
267 let local_var_configuration = &self.configuration;
268
269 let local_var_client = &local_var_configuration.client;
270
271 let local_var_uri_str = format!("{}/folders", local_var_configuration.base_path);
272 let mut local_var_req_builder =
273 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
274
275 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
276 local_var_req_builder = local_var_req_builder
277 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
278 }
279 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
280 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
281 };
282 local_var_req_builder = local_var_req_builder.json(&folder_request_model);
283
284 let local_var_req = local_var_req_builder.build()?;
285 let local_var_resp = local_var_client.execute(local_var_req).await?;
286
287 let local_var_status = local_var_resp.status();
288 let local_var_content_type = local_var_resp
289 .headers()
290 .get("content-type")
291 .and_then(|v| v.to_str().ok())
292 .unwrap_or("application/octet-stream");
293 let local_var_content_type = super::ContentType::from(local_var_content_type);
294 let local_var_content = local_var_resp.text().await?;
295
296 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
297 match local_var_content_type {
298 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
299 ContentType::Text => {
300 return Err(Error::from(serde_json::Error::custom(
301 "Received `text/plain` content type response that cannot be converted to `models::FolderResponseModel`",
302 )));
303 }
304 ContentType::Unsupported(local_var_unknown_type) => {
305 return Err(Error::from(serde_json::Error::custom(format!(
306 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::FolderResponseModel`"
307 ))));
308 }
309 }
310 } else {
311 let local_var_entity: Option<PostError> = serde_json::from_str(&local_var_content).ok();
312 let local_var_error = ResponseContent {
313 status: local_var_status,
314 content: local_var_content,
315 entity: local_var_entity,
316 };
317 Err(Error::ResponseError(local_var_error))
318 }
319 }
320
321 async fn put<'a>(
322 &self,
323 id: &'a str,
324 folder_request_model: Option<models::FolderRequestModel>,
325 ) -> Result<models::FolderResponseModel, Error<PutError>> {
326 let local_var_configuration = &self.configuration;
327
328 let local_var_client = &local_var_configuration.client;
329
330 let local_var_uri_str = format!(
331 "{}/folders/{id}",
332 local_var_configuration.base_path,
333 id = crate::apis::urlencode(id)
334 );
335 let mut local_var_req_builder =
336 local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
337
338 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
339 local_var_req_builder = local_var_req_builder
340 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
341 }
342 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
343 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
344 };
345 local_var_req_builder = local_var_req_builder.json(&folder_request_model);
346
347 let local_var_req = local_var_req_builder.build()?;
348 let local_var_resp = local_var_client.execute(local_var_req).await?;
349
350 let local_var_status = local_var_resp.status();
351 let local_var_content_type = local_var_resp
352 .headers()
353 .get("content-type")
354 .and_then(|v| v.to_str().ok())
355 .unwrap_or("application/octet-stream");
356 let local_var_content_type = super::ContentType::from(local_var_content_type);
357 let local_var_content = local_var_resp.text().await?;
358
359 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
360 match local_var_content_type {
361 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
362 ContentType::Text => {
363 return Err(Error::from(serde_json::Error::custom(
364 "Received `text/plain` content type response that cannot be converted to `models::FolderResponseModel`",
365 )));
366 }
367 ContentType::Unsupported(local_var_unknown_type) => {
368 return Err(Error::from(serde_json::Error::custom(format!(
369 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::FolderResponseModel`"
370 ))));
371 }
372 }
373 } else {
374 let local_var_entity: Option<PutError> = serde_json::from_str(&local_var_content).ok();
375 let local_var_error = ResponseContent {
376 status: local_var_status,
377 content: local_var_content,
378 entity: local_var_entity,
379 };
380 Err(Error::ResponseError(local_var_error))
381 }
382 }
383}
384
385#[derive(Debug, Clone, Serialize, Deserialize)]
387#[serde(untagged)]
388pub enum DeleteError {
389 UnknownValue(serde_json::Value),
390}
391#[derive(Debug, Clone, Serialize, Deserialize)]
393#[serde(untagged)]
394pub enum DeleteAllError {
395 UnknownValue(serde_json::Value),
396}
397#[derive(Debug, Clone, Serialize, Deserialize)]
399#[serde(untagged)]
400pub enum GetError {
401 UnknownValue(serde_json::Value),
402}
403#[derive(Debug, Clone, Serialize, Deserialize)]
405#[serde(untagged)]
406pub enum GetAllError {
407 UnknownValue(serde_json::Value),
408}
409#[derive(Debug, Clone, Serialize, Deserialize)]
411#[serde(untagged)]
412pub enum PostError {
413 UnknownValue(serde_json::Value),
414}
415#[derive(Debug, Clone, Serialize, Deserialize)]
417#[serde(untagged)]
418pub enum PutError {
419 UnknownValue(serde_json::Value),
420}