Skip to main content

spatio_sdk/apis/
folders_api.rs

1/*
2 * SpatioAPI
3 *
4 * The REST API that owns every resource in your Spatio workspace: notes, sheets, slides, tasks, calendar events, mail, chat, files, and contacts. SpatioMCP wraps this API; Spatio Desktop reads from it. You can call it directly from your own code.  All requests must be authenticated with a Personal Access Token (`Authorization: Bearer pat_...`) or an OAuth 2.1 access token, and use HTTPS.  Official SDKs (MIT, generated from this spec on every release):  - TypeScript: https://github.com/spatio-labs/spatio-ts (`npm install @spatio-labs/spatio-ts`) - Python: https://github.com/spatio-labs/spatio-py (`pip install spatio-sdk`) - Go: https://github.com/spatio-labs/spatio-go (`go get github.com/spatio-labs/spatio-go`)  This specification is generated from the platform-service Go source on every push to `main`. The spec, not hand-written documentation, is the source of truth: server stubs and SDKs are generated from it, and any drift between the spec and the running service fails CI. 
5 *
6 * The version of the OpenAPI document: v1
7 * Contact: hello@spatio.app
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 [`create_email_folder`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateEmailFolderError {
22    Status401(models::ApiError),
23    UnknownValue(serde_json::Value),
24}
25
26/// struct for typed errors of method [`delete_email_folder`]
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum DeleteEmailFolderError {
30    Status401(models::ApiError),
31    UnknownValue(serde_json::Value),
32}
33
34/// struct for typed errors of method [`list_email_folders`]
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum ListEmailFoldersError {
38    Status401(models::ApiError),
39    UnknownValue(serde_json::Value),
40}
41
42/// struct for typed errors of method [`list_folder_emails`]
43#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum ListFolderEmailsError {
46    Status401(models::ApiError),
47    UnknownValue(serde_json::Value),
48}
49
50/// struct for typed errors of method [`move_emails_to_folder`]
51#[derive(Debug, Clone, Serialize, Deserialize)]
52#[serde(untagged)]
53pub enum MoveEmailsToFolderError {
54    Status401(models::ApiError),
55    UnknownValue(serde_json::Value),
56}
57
58/// struct for typed errors of method [`update_email_folder`]
59#[derive(Debug, Clone, Serialize, Deserialize)]
60#[serde(untagged)]
61pub enum UpdateEmailFolderError {
62    Status401(models::ApiError),
63    UnknownValue(serde_json::Value),
64}
65
66
67pub async fn create_email_folder(configuration: &configuration::Configuration, create_email_folder_request: models::CreateEmailFolderRequest) -> Result<models::EmailFolder, Error<CreateEmailFolderError>> {
68    // add a prefix to parameters to efficiently prevent name collisions
69    let p_body_create_email_folder_request = create_email_folder_request;
70
71    let uri_str = format!("{}/v1/folders", configuration.base_path);
72    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
73
74    if let Some(ref user_agent) = configuration.user_agent {
75        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
76    }
77    if let Some(ref token) = configuration.bearer_access_token {
78        req_builder = req_builder.bearer_auth(token.to_owned());
79    };
80    req_builder = req_builder.json(&p_body_create_email_folder_request);
81
82    let req = req_builder.build()?;
83    let resp = configuration.client.execute(req).await?;
84
85    let status = resp.status();
86    let content_type = resp
87        .headers()
88        .get("content-type")
89        .and_then(|v| v.to_str().ok())
90        .unwrap_or("application/octet-stream");
91    let content_type = super::ContentType::from(content_type);
92
93    if !status.is_client_error() && !status.is_server_error() {
94        let content = resp.text().await?;
95        match content_type {
96            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
97            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::EmailFolder`"))),
98            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::EmailFolder`")))),
99        }
100    } else {
101        let content = resp.text().await?;
102        let entity: Option<CreateEmailFolderError> = serde_json::from_str(&content).ok();
103        Err(Error::ResponseError(ResponseContent { status, content, entity }))
104    }
105}
106
107pub async fn delete_email_folder(configuration: &configuration::Configuration, id: &str) -> Result<(), Error<DeleteEmailFolderError>> {
108    // add a prefix to parameters to efficiently prevent name collisions
109    let p_path_id = id;
110
111    let uri_str = format!("{}/v1/folders/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
112    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
113
114    if let Some(ref user_agent) = configuration.user_agent {
115        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
116    }
117    if let Some(ref token) = configuration.bearer_access_token {
118        req_builder = req_builder.bearer_auth(token.to_owned());
119    };
120
121    let req = req_builder.build()?;
122    let resp = configuration.client.execute(req).await?;
123
124    let status = resp.status();
125
126    if !status.is_client_error() && !status.is_server_error() {
127        Ok(())
128    } else {
129        let content = resp.text().await?;
130        let entity: Option<DeleteEmailFolderError> = serde_json::from_str(&content).ok();
131        Err(Error::ResponseError(ResponseContent { status, content, entity }))
132    }
133}
134
135pub async fn list_email_folders(configuration: &configuration::Configuration, ) -> Result<models::EmailFolderListResponse, Error<ListEmailFoldersError>> {
136
137    let uri_str = format!("{}/v1/folders", configuration.base_path);
138    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
139
140    if let Some(ref user_agent) = configuration.user_agent {
141        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
142    }
143    if let Some(ref token) = configuration.bearer_access_token {
144        req_builder = req_builder.bearer_auth(token.to_owned());
145    };
146
147    let req = req_builder.build()?;
148    let resp = configuration.client.execute(req).await?;
149
150    let status = resp.status();
151    let content_type = resp
152        .headers()
153        .get("content-type")
154        .and_then(|v| v.to_str().ok())
155        .unwrap_or("application/octet-stream");
156    let content_type = super::ContentType::from(content_type);
157
158    if !status.is_client_error() && !status.is_server_error() {
159        let content = resp.text().await?;
160        match content_type {
161            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
162            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::EmailFolderListResponse`"))),
163            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::EmailFolderListResponse`")))),
164        }
165    } else {
166        let content = resp.text().await?;
167        let entity: Option<ListEmailFoldersError> = serde_json::from_str(&content).ok();
168        Err(Error::ResponseError(ResponseContent { status, content, entity }))
169    }
170}
171
172pub async fn list_folder_emails(configuration: &configuration::Configuration, id: &str) -> Result<std::collections::HashMap<String, serde_json::Value>, Error<ListFolderEmailsError>> {
173    // add a prefix to parameters to efficiently prevent name collisions
174    let p_path_id = id;
175
176    let uri_str = format!("{}/v1/folders/{id}/emails", configuration.base_path, id=crate::apis::urlencode(p_path_id));
177    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
178
179    if let Some(ref user_agent) = configuration.user_agent {
180        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
181    }
182    if let Some(ref token) = configuration.bearer_access_token {
183        req_builder = req_builder.bearer_auth(token.to_owned());
184    };
185
186    let req = req_builder.build()?;
187    let resp = configuration.client.execute(req).await?;
188
189    let status = resp.status();
190    let content_type = resp
191        .headers()
192        .get("content-type")
193        .and_then(|v| v.to_str().ok())
194        .unwrap_or("application/octet-stream");
195    let content_type = super::ContentType::from(content_type);
196
197    if !status.is_client_error() && !status.is_server_error() {
198        let content = resp.text().await?;
199        match content_type {
200            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
201            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `std::collections::HashMap&lt;String, serde_json::Value&gt;`"))),
202            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `std::collections::HashMap&lt;String, serde_json::Value&gt;`")))),
203        }
204    } else {
205        let content = resp.text().await?;
206        let entity: Option<ListFolderEmailsError> = serde_json::from_str(&content).ok();
207        Err(Error::ResponseError(ResponseContent { status, content, entity }))
208    }
209}
210
211pub async fn move_emails_to_folder(configuration: &configuration::Configuration, id: &str, move_emails_request: models::MoveEmailsRequest) -> Result<std::collections::HashMap<String, serde_json::Value>, Error<MoveEmailsToFolderError>> {
212    // add a prefix to parameters to efficiently prevent name collisions
213    let p_path_id = id;
214    let p_body_move_emails_request = move_emails_request;
215
216    let uri_str = format!("{}/v1/folders/{id}/emails", configuration.base_path, id=crate::apis::urlencode(p_path_id));
217    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
218
219    if let Some(ref user_agent) = configuration.user_agent {
220        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
221    }
222    if let Some(ref token) = configuration.bearer_access_token {
223        req_builder = req_builder.bearer_auth(token.to_owned());
224    };
225    req_builder = req_builder.json(&p_body_move_emails_request);
226
227    let req = req_builder.build()?;
228    let resp = configuration.client.execute(req).await?;
229
230    let status = resp.status();
231    let content_type = resp
232        .headers()
233        .get("content-type")
234        .and_then(|v| v.to_str().ok())
235        .unwrap_or("application/octet-stream");
236    let content_type = super::ContentType::from(content_type);
237
238    if !status.is_client_error() && !status.is_server_error() {
239        let content = resp.text().await?;
240        match content_type {
241            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
242            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `std::collections::HashMap&lt;String, serde_json::Value&gt;`"))),
243            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `std::collections::HashMap&lt;String, serde_json::Value&gt;`")))),
244        }
245    } else {
246        let content = resp.text().await?;
247        let entity: Option<MoveEmailsToFolderError> = serde_json::from_str(&content).ok();
248        Err(Error::ResponseError(ResponseContent { status, content, entity }))
249    }
250}
251
252pub async fn update_email_folder(configuration: &configuration::Configuration, id: &str, update_email_folder_request: models::UpdateEmailFolderRequest) -> Result<models::EmailFolder, Error<UpdateEmailFolderError>> {
253    // add a prefix to parameters to efficiently prevent name collisions
254    let p_path_id = id;
255    let p_body_update_email_folder_request = update_email_folder_request;
256
257    let uri_str = format!("{}/v1/folders/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
258    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
259
260    if let Some(ref user_agent) = configuration.user_agent {
261        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
262    }
263    if let Some(ref token) = configuration.bearer_access_token {
264        req_builder = req_builder.bearer_auth(token.to_owned());
265    };
266    req_builder = req_builder.json(&p_body_update_email_folder_request);
267
268    let req = req_builder.build()?;
269    let resp = configuration.client.execute(req).await?;
270
271    let status = resp.status();
272    let content_type = resp
273        .headers()
274        .get("content-type")
275        .and_then(|v| v.to_str().ok())
276        .unwrap_or("application/octet-stream");
277    let content_type = super::ContentType::from(content_type);
278
279    if !status.is_client_error() && !status.is_server_error() {
280        let content = resp.text().await?;
281        match content_type {
282            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
283            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::EmailFolder`"))),
284            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::EmailFolder`")))),
285        }
286    } else {
287        let content = resp.text().await?;
288        let entity: Option<UpdateEmailFolderError> = serde_json::from_str(&content).ok();
289        Err(Error::ResponseError(ResponseContent { status, content, entity }))
290    }
291}
292