Skip to main content

spatio_sdk/apis/
account_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 [`change_password`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum ChangePasswordError {
22    Status400(models::ApiError),
23    Status401(models::ApiError),
24    UnknownValue(serde_json::Value),
25}
26
27/// struct for typed errors of method [`consume_agent_task`]
28#[derive(Debug, Clone, Serialize, Deserialize)]
29#[serde(untagged)]
30pub enum ConsumeAgentTaskError {
31    Status401(models::ApiError),
32    Status402(models::ApiError),
33    Status429(models::ApiError),
34    UnknownValue(serde_json::Value),
35}
36
37/// struct for typed errors of method [`get_account_plan`]
38#[derive(Debug, Clone, Serialize, Deserialize)]
39#[serde(untagged)]
40pub enum GetAccountPlanError {
41    Status401(models::ApiError),
42    UnknownValue(serde_json::Value),
43}
44
45/// struct for typed errors of method [`get_account_tier`]
46#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum GetAccountTierError {
49    Status401(models::ApiError),
50    UnknownValue(serde_json::Value),
51}
52
53/// struct for typed errors of method [`get_account_usage`]
54#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum GetAccountUsageError {
57    Status401(models::ApiError),
58    UnknownValue(serde_json::Value),
59}
60
61/// struct for typed errors of method [`get_agent_task_usage`]
62#[derive(Debug, Clone, Serialize, Deserialize)]
63#[serde(untagged)]
64pub enum GetAgentTaskUsageError {
65    Status401(models::ApiError),
66    UnknownValue(serde_json::Value),
67}
68
69/// struct for typed errors of method [`get_sign_in_methods`]
70#[derive(Debug, Clone, Serialize, Deserialize)]
71#[serde(untagged)]
72pub enum GetSignInMethodsError {
73    Status401(models::ApiError),
74    UnknownValue(serde_json::Value),
75}
76
77/// struct for typed errors of method [`list_connected_apps`]
78#[derive(Debug, Clone, Serialize, Deserialize)]
79#[serde(untagged)]
80pub enum ListConnectedAppsError {
81    UnknownValue(serde_json::Value),
82}
83
84/// struct for typed errors of method [`list_sessions`]
85#[derive(Debug, Clone, Serialize, Deserialize)]
86#[serde(untagged)]
87pub enum ListSessionsError {
88    Status401(models::ApiError),
89    UnknownValue(serde_json::Value),
90}
91
92/// struct for typed errors of method [`revoke_connected_app`]
93#[derive(Debug, Clone, Serialize, Deserialize)]
94#[serde(untagged)]
95pub enum RevokeConnectedAppError {
96    Status404(),
97    UnknownValue(serde_json::Value),
98}
99
100/// struct for typed errors of method [`revoke_other_sessions`]
101#[derive(Debug, Clone, Serialize, Deserialize)]
102#[serde(untagged)]
103pub enum RevokeOtherSessionsError {
104    Status401(models::ApiError),
105    UnknownValue(serde_json::Value),
106}
107
108/// struct for typed errors of method [`revoke_session`]
109#[derive(Debug, Clone, Serialize, Deserialize)]
110#[serde(untagged)]
111pub enum RevokeSessionError {
112    Status401(models::ApiError),
113    Status404(models::ApiError),
114    UnknownValue(serde_json::Value),
115}
116
117
118pub async fn change_password(configuration: &configuration::Configuration, change_password_request: models::ChangePasswordRequest) -> Result<(), Error<ChangePasswordError>> {
119    // add a prefix to parameters to efficiently prevent name collisions
120    let p_body_change_password_request = change_password_request;
121
122    let uri_str = format!("{}/v1/account/security/password", configuration.base_path);
123    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
124
125    if let Some(ref user_agent) = configuration.user_agent {
126        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
127    }
128    if let Some(ref token) = configuration.bearer_access_token {
129        req_builder = req_builder.bearer_auth(token.to_owned());
130    };
131    req_builder = req_builder.json(&p_body_change_password_request);
132
133    let req = req_builder.build()?;
134    let resp = configuration.client.execute(req).await?;
135
136    let status = resp.status();
137
138    if !status.is_client_error() && !status.is_server_error() {
139        Ok(())
140    } else {
141        let content = resp.text().await?;
142        let entity: Option<ChangePasswordError> = serde_json::from_str(&content).ok();
143        Err(Error::ResponseError(ResponseContent { status, content, entity }))
144    }
145}
146
147pub async fn consume_agent_task(configuration: &configuration::Configuration, ) -> Result<models::ConsumeAgentTaskResponse, Error<ConsumeAgentTaskError>> {
148
149    let uri_str = format!("{}/v1/account/usage/consume-agent-task", configuration.base_path);
150    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
151
152    if let Some(ref user_agent) = configuration.user_agent {
153        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
154    }
155    if let Some(ref token) = configuration.bearer_access_token {
156        req_builder = req_builder.bearer_auth(token.to_owned());
157    };
158
159    let req = req_builder.build()?;
160    let resp = configuration.client.execute(req).await?;
161
162    let status = resp.status();
163    let content_type = resp
164        .headers()
165        .get("content-type")
166        .and_then(|v| v.to_str().ok())
167        .unwrap_or("application/octet-stream");
168    let content_type = super::ContentType::from(content_type);
169
170    if !status.is_client_error() && !status.is_server_error() {
171        let content = resp.text().await?;
172        match content_type {
173            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
174            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ConsumeAgentTaskResponse`"))),
175            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::ConsumeAgentTaskResponse`")))),
176        }
177    } else {
178        let content = resp.text().await?;
179        let entity: Option<ConsumeAgentTaskError> = serde_json::from_str(&content).ok();
180        Err(Error::ResponseError(ResponseContent { status, content, entity }))
181    }
182}
183
184pub async fn get_account_plan(configuration: &configuration::Configuration, ) -> Result<models::AccountPlan, Error<GetAccountPlanError>> {
185
186    let uri_str = format!("{}/v1/account/plan", configuration.base_path);
187    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
188
189    if let Some(ref user_agent) = configuration.user_agent {
190        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
191    }
192    if let Some(ref token) = configuration.bearer_access_token {
193        req_builder = req_builder.bearer_auth(token.to_owned());
194    };
195
196    let req = req_builder.build()?;
197    let resp = configuration.client.execute(req).await?;
198
199    let status = resp.status();
200    let content_type = resp
201        .headers()
202        .get("content-type")
203        .and_then(|v| v.to_str().ok())
204        .unwrap_or("application/octet-stream");
205    let content_type = super::ContentType::from(content_type);
206
207    if !status.is_client_error() && !status.is_server_error() {
208        let content = resp.text().await?;
209        match content_type {
210            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
211            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AccountPlan`"))),
212            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::AccountPlan`")))),
213        }
214    } else {
215        let content = resp.text().await?;
216        let entity: Option<GetAccountPlanError> = serde_json::from_str(&content).ok();
217        Err(Error::ResponseError(ResponseContent { status, content, entity }))
218    }
219}
220
221pub async fn get_account_tier(configuration: &configuration::Configuration, ) -> Result<models::AccountTierDetails, Error<GetAccountTierError>> {
222
223    let uri_str = format!("{}/v1/account/tier", configuration.base_path);
224    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
225
226    if let Some(ref user_agent) = configuration.user_agent {
227        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
228    }
229    if let Some(ref token) = configuration.bearer_access_token {
230        req_builder = req_builder.bearer_auth(token.to_owned());
231    };
232
233    let req = req_builder.build()?;
234    let resp = configuration.client.execute(req).await?;
235
236    let status = resp.status();
237    let content_type = resp
238        .headers()
239        .get("content-type")
240        .and_then(|v| v.to_str().ok())
241        .unwrap_or("application/octet-stream");
242    let content_type = super::ContentType::from(content_type);
243
244    if !status.is_client_error() && !status.is_server_error() {
245        let content = resp.text().await?;
246        match content_type {
247            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
248            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AccountTierDetails`"))),
249            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::AccountTierDetails`")))),
250        }
251    } else {
252        let content = resp.text().await?;
253        let entity: Option<GetAccountTierError> = serde_json::from_str(&content).ok();
254        Err(Error::ResponseError(ResponseContent { status, content, entity }))
255    }
256}
257
258pub async fn get_account_usage(configuration: &configuration::Configuration, ) -> Result<models::AccountUsage, Error<GetAccountUsageError>> {
259
260    let uri_str = format!("{}/v1/account/usage", configuration.base_path);
261    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
262
263    if let Some(ref user_agent) = configuration.user_agent {
264        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
265    }
266    if let Some(ref token) = configuration.bearer_access_token {
267        req_builder = req_builder.bearer_auth(token.to_owned());
268    };
269
270    let req = req_builder.build()?;
271    let resp = configuration.client.execute(req).await?;
272
273    let status = resp.status();
274    let content_type = resp
275        .headers()
276        .get("content-type")
277        .and_then(|v| v.to_str().ok())
278        .unwrap_or("application/octet-stream");
279    let content_type = super::ContentType::from(content_type);
280
281    if !status.is_client_error() && !status.is_server_error() {
282        let content = resp.text().await?;
283        match content_type {
284            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
285            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AccountUsage`"))),
286            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::AccountUsage`")))),
287        }
288    } else {
289        let content = resp.text().await?;
290        let entity: Option<GetAccountUsageError> = serde_json::from_str(&content).ok();
291        Err(Error::ResponseError(ResponseContent { status, content, entity }))
292    }
293}
294
295pub async fn get_agent_task_usage(configuration: &configuration::Configuration, ) -> Result<models::AgentTaskUsage, Error<GetAgentTaskUsageError>> {
296
297    let uri_str = format!("{}/v1/account/usage/agent-tasks", configuration.base_path);
298    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
299
300    if let Some(ref user_agent) = configuration.user_agent {
301        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
302    }
303    if let Some(ref token) = configuration.bearer_access_token {
304        req_builder = req_builder.bearer_auth(token.to_owned());
305    };
306
307    let req = req_builder.build()?;
308    let resp = configuration.client.execute(req).await?;
309
310    let status = resp.status();
311    let content_type = resp
312        .headers()
313        .get("content-type")
314        .and_then(|v| v.to_str().ok())
315        .unwrap_or("application/octet-stream");
316    let content_type = super::ContentType::from(content_type);
317
318    if !status.is_client_error() && !status.is_server_error() {
319        let content = resp.text().await?;
320        match content_type {
321            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
322            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AgentTaskUsage`"))),
323            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::AgentTaskUsage`")))),
324        }
325    } else {
326        let content = resp.text().await?;
327        let entity: Option<GetAgentTaskUsageError> = serde_json::from_str(&content).ok();
328        Err(Error::ResponseError(ResponseContent { status, content, entity }))
329    }
330}
331
332pub async fn get_sign_in_methods(configuration: &configuration::Configuration, ) -> Result<models::SignInMethods, Error<GetSignInMethodsError>> {
333
334    let uri_str = format!("{}/v1/account/security/sign-in-methods", configuration.base_path);
335    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
336
337    if let Some(ref user_agent) = configuration.user_agent {
338        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
339    }
340    if let Some(ref token) = configuration.bearer_access_token {
341        req_builder = req_builder.bearer_auth(token.to_owned());
342    };
343
344    let req = req_builder.build()?;
345    let resp = configuration.client.execute(req).await?;
346
347    let status = resp.status();
348    let content_type = resp
349        .headers()
350        .get("content-type")
351        .and_then(|v| v.to_str().ok())
352        .unwrap_or("application/octet-stream");
353    let content_type = super::ContentType::from(content_type);
354
355    if !status.is_client_error() && !status.is_server_error() {
356        let content = resp.text().await?;
357        match content_type {
358            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
359            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SignInMethods`"))),
360            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::SignInMethods`")))),
361        }
362    } else {
363        let content = resp.text().await?;
364        let entity: Option<GetSignInMethodsError> = serde_json::from_str(&content).ok();
365        Err(Error::ResponseError(ResponseContent { status, content, entity }))
366    }
367}
368
369pub async fn list_connected_apps(configuration: &configuration::Configuration, ) -> Result<models::ConnectedAppsListResponse, Error<ListConnectedAppsError>> {
370
371    let uri_str = format!("{}/v1/account/connected-apps", configuration.base_path);
372    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
373
374    if let Some(ref user_agent) = configuration.user_agent {
375        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
376    }
377    if let Some(ref token) = configuration.bearer_access_token {
378        req_builder = req_builder.bearer_auth(token.to_owned());
379    };
380
381    let req = req_builder.build()?;
382    let resp = configuration.client.execute(req).await?;
383
384    let status = resp.status();
385    let content_type = resp
386        .headers()
387        .get("content-type")
388        .and_then(|v| v.to_str().ok())
389        .unwrap_or("application/octet-stream");
390    let content_type = super::ContentType::from(content_type);
391
392    if !status.is_client_error() && !status.is_server_error() {
393        let content = resp.text().await?;
394        match content_type {
395            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
396            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ConnectedAppsListResponse`"))),
397            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::ConnectedAppsListResponse`")))),
398        }
399    } else {
400        let content = resp.text().await?;
401        let entity: Option<ListConnectedAppsError> = serde_json::from_str(&content).ok();
402        Err(Error::ResponseError(ResponseContent { status, content, entity }))
403    }
404}
405
406pub async fn list_sessions(configuration: &configuration::Configuration, ) -> Result<models::SessionListResponse, Error<ListSessionsError>> {
407
408    let uri_str = format!("{}/v1/account/security/sessions", configuration.base_path);
409    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
410
411    if let Some(ref user_agent) = configuration.user_agent {
412        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
413    }
414    if let Some(ref token) = configuration.bearer_access_token {
415        req_builder = req_builder.bearer_auth(token.to_owned());
416    };
417
418    let req = req_builder.build()?;
419    let resp = configuration.client.execute(req).await?;
420
421    let status = resp.status();
422    let content_type = resp
423        .headers()
424        .get("content-type")
425        .and_then(|v| v.to_str().ok())
426        .unwrap_or("application/octet-stream");
427    let content_type = super::ContentType::from(content_type);
428
429    if !status.is_client_error() && !status.is_server_error() {
430        let content = resp.text().await?;
431        match content_type {
432            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
433            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SessionListResponse`"))),
434            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::SessionListResponse`")))),
435        }
436    } else {
437        let content = resp.text().await?;
438        let entity: Option<ListSessionsError> = serde_json::from_str(&content).ok();
439        Err(Error::ResponseError(ResponseContent { status, content, entity }))
440    }
441}
442
443pub async fn revoke_connected_app(configuration: &configuration::Configuration, client_id: &str) -> Result<(), Error<RevokeConnectedAppError>> {
444    // add a prefix to parameters to efficiently prevent name collisions
445    let p_path_client_id = client_id;
446
447    let uri_str = format!("{}/v1/account/connected-apps/{client_id}", configuration.base_path, client_id=crate::apis::urlencode(p_path_client_id));
448    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
449
450    if let Some(ref user_agent) = configuration.user_agent {
451        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
452    }
453    if let Some(ref token) = configuration.bearer_access_token {
454        req_builder = req_builder.bearer_auth(token.to_owned());
455    };
456
457    let req = req_builder.build()?;
458    let resp = configuration.client.execute(req).await?;
459
460    let status = resp.status();
461
462    if !status.is_client_error() && !status.is_server_error() {
463        Ok(())
464    } else {
465        let content = resp.text().await?;
466        let entity: Option<RevokeConnectedAppError> = serde_json::from_str(&content).ok();
467        Err(Error::ResponseError(ResponseContent { status, content, entity }))
468    }
469}
470
471pub async fn revoke_other_sessions(configuration: &configuration::Configuration, ) -> Result<models::RevokeOtherSessionsResponse, Error<RevokeOtherSessionsError>> {
472
473    let uri_str = format!("{}/v1/account/security/sessions/revoke-others", configuration.base_path);
474    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
475
476    if let Some(ref user_agent) = configuration.user_agent {
477        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
478    }
479    if let Some(ref token) = configuration.bearer_access_token {
480        req_builder = req_builder.bearer_auth(token.to_owned());
481    };
482
483    let req = req_builder.build()?;
484    let resp = configuration.client.execute(req).await?;
485
486    let status = resp.status();
487    let content_type = resp
488        .headers()
489        .get("content-type")
490        .and_then(|v| v.to_str().ok())
491        .unwrap_or("application/octet-stream");
492    let content_type = super::ContentType::from(content_type);
493
494    if !status.is_client_error() && !status.is_server_error() {
495        let content = resp.text().await?;
496        match content_type {
497            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
498            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RevokeOtherSessionsResponse`"))),
499            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::RevokeOtherSessionsResponse`")))),
500        }
501    } else {
502        let content = resp.text().await?;
503        let entity: Option<RevokeOtherSessionsError> = serde_json::from_str(&content).ok();
504        Err(Error::ResponseError(ResponseContent { status, content, entity }))
505    }
506}
507
508pub async fn revoke_session(configuration: &configuration::Configuration, id: &str) -> Result<(), Error<RevokeSessionError>> {
509    // add a prefix to parameters to efficiently prevent name collisions
510    let p_path_id = id;
511
512    let uri_str = format!("{}/v1/account/security/sessions/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
513    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
514
515    if let Some(ref user_agent) = configuration.user_agent {
516        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
517    }
518    if let Some(ref token) = configuration.bearer_access_token {
519        req_builder = req_builder.bearer_auth(token.to_owned());
520    };
521
522    let req = req_builder.build()?;
523    let resp = configuration.client.execute(req).await?;
524
525    let status = resp.status();
526
527    if !status.is_client_error() && !status.is_server_error() {
528        Ok(())
529    } else {
530        let content = resp.text().await?;
531        let entity: Option<RevokeSessionError> = serde_json::from_str(&content).ok();
532        Err(Error::ResponseError(ResponseContent { status, content, entity }))
533    }
534}
535