memos_api/apis/
inbox_service_api.rs

1/*
2 * Memos API
3 *
4 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5 *
6 * The version of the OpenAPI document: 1.0.0
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method [`inbox_service_delete_inbox`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum InboxServiceDeleteInboxError {
22    DefaultResponse(models::GooglerpcStatus),
23    UnknownValue(serde_json::Value),
24}
25
26/// struct for typed errors of method [`inbox_service_list_inboxes`]
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum InboxServiceListInboxesError {
30    DefaultResponse(models::GooglerpcStatus),
31    UnknownValue(serde_json::Value),
32}
33
34/// struct for typed errors of method [`inbox_service_update_inbox`]
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum InboxServiceUpdateInboxError {
38    DefaultResponse(models::GooglerpcStatus),
39    UnknownValue(serde_json::Value),
40}
41
42
43pub fn inbox_service_delete_inbox(configuration: &configuration::Configuration, name_2: &str) -> Result<serde_json::Value, Error<InboxServiceDeleteInboxError>> {
44    let local_var_configuration = configuration;
45
46    let local_var_client = &local_var_configuration.client;
47
48    let local_var_uri_str = format!("{}/api/v1/{name_2}", local_var_configuration.base_path, name_2=crate::apis::urlencode(name_2));
49    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
50
51    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
52        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
53    }
54
55    let local_var_req = local_var_req_builder.build()?;
56    let local_var_resp = local_var_client.execute(local_var_req)?;
57
58    let local_var_status = local_var_resp.status();
59    let local_var_content = local_var_resp.text()?;
60
61    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
62        serde_json::from_str(&local_var_content).map_err(Error::from)
63    } else {
64        let local_var_entity: Option<InboxServiceDeleteInboxError> = serde_json::from_str(&local_var_content).ok();
65        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
66        Err(Error::ResponseError(local_var_error))
67    }
68}
69
70pub fn inbox_service_list_inboxes(configuration: &configuration::Configuration, user: Option<&str>) -> Result<models::V1ListInboxesResponse, Error<InboxServiceListInboxesError>> {
71    let local_var_configuration = configuration;
72
73    let local_var_client = &local_var_configuration.client;
74
75    let local_var_uri_str = format!("{}/api/v1/inboxes", local_var_configuration.base_path);
76    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
77
78    if let Some(ref local_var_str) = user {
79        local_var_req_builder = local_var_req_builder.query(&[("user", &local_var_str.to_string())]);
80    }
81    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
82        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
83    }
84
85    let local_var_req = local_var_req_builder.build()?;
86    let local_var_resp = local_var_client.execute(local_var_req)?;
87
88    let local_var_status = local_var_resp.status();
89    let local_var_content = local_var_resp.text()?;
90
91    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
92        serde_json::from_str(&local_var_content).map_err(Error::from)
93    } else {
94        let local_var_entity: Option<InboxServiceListInboxesError> = serde_json::from_str(&local_var_content).ok();
95        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
96        Err(Error::ResponseError(local_var_error))
97    }
98}
99
100pub fn inbox_service_update_inbox(configuration: &configuration::Configuration, inbox_name: &str, inbox: models::InboxServiceUpdateInboxRequest) -> Result<models::V1Inbox, Error<InboxServiceUpdateInboxError>> {
101    let local_var_configuration = configuration;
102
103    let local_var_client = &local_var_configuration.client;
104
105    let local_var_uri_str = format!("{}/api/v1/{inbox_name}", local_var_configuration.base_path, inbox_name=crate::apis::urlencode(inbox_name));
106    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
107
108    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
109        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
110    }
111    local_var_req_builder = local_var_req_builder.json(&inbox);
112
113    let local_var_req = local_var_req_builder.build()?;
114    let local_var_resp = local_var_client.execute(local_var_req)?;
115
116    let local_var_status = local_var_resp.status();
117    let local_var_content = local_var_resp.text()?;
118
119    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
120        serde_json::from_str(&local_var_content).map_err(Error::from)
121    } else {
122        let local_var_entity: Option<InboxServiceUpdateInboxError> = serde_json::from_str(&local_var_content).ok();
123        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
124        Err(Error::ResponseError(local_var_error))
125    }
126}
127