Skip to main content

agentcat_api/apis/
notifications_api.rs

1/*
2 * AgentCat API
3 *
4 * API for AgentCat application
5 *
6 * The version of the OpenAPI document: v1
7 * 
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/// struct for passing parameters to the method [`unsubscribe_notification`]
18#[derive(Clone, Debug)]
19pub struct UnsubscribeNotificationParams {
20    /// Signed unsubscribe token. May also be passed in the request body.
21    pub token: Option<String>,
22    pub unsubscribe_request_request: Option<models::UnsubscribeRequestRequest>
23}
24
25/// struct for passing parameters to the method [`verify_email_channel`]
26#[derive(Clone, Debug)]
27pub struct VerifyEmailChannelParams {
28    pub token: Option<String>,
29    pub email_channel_verify_request: Option<models::EmailChannelVerifyRequest>
30}
31
32
33/// struct for typed errors of method [`unsubscribe_notification`]
34#[derive(Debug, Clone, Serialize, Deserialize)]
35#[serde(untagged)]
36pub enum UnsubscribeNotificationError {
37    Status400(String),
38    Status404(String),
39    Status401(models::Error),
40    Status403(models::Error),
41    UnknownValue(serde_json::Value),
42}
43
44/// struct for typed errors of method [`verify_email_channel`]
45#[derive(Debug, Clone, Serialize, Deserialize)]
46#[serde(untagged)]
47pub enum VerifyEmailChannelError {
48    Status400(std::collections::HashMap<String, models::ValidationErrorValue>),
49    Status401(models::Error),
50    Status403(models::Error),
51    UnknownValue(serde_json::Value),
52}
53
54
55/// Anonymous endpoint reached from email unsubscribe links and the List-Unsubscribe header POST. The token encodes the user and the notification type to disable. Response bodies are plain text.
56pub async fn unsubscribe_notification(configuration: &configuration::Configuration, params: UnsubscribeNotificationParams) -> Result<String, Error<UnsubscribeNotificationError>> {
57
58    let uri_str = format!("{}/v1/public/notifications/unsubscribe", configuration.base_path);
59    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
60
61    if let Some(ref param_value) = params.token {
62        req_builder = req_builder.query(&[("token", &param_value.to_string())]);
63    }
64    if let Some(ref user_agent) = configuration.user_agent {
65        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
66    }
67    req_builder = req_builder.json(&params.unsubscribe_request_request);
68
69    let req = req_builder.build()?;
70    let resp = configuration.client.execute(req).await?;
71
72    let status = resp.status();
73    let content_type = resp
74        .headers()
75        .get("content-type")
76        .and_then(|v| v.to_str().ok())
77        .unwrap_or("application/octet-stream");
78    let content_type = super::ContentType::from(content_type);
79
80    if !status.is_client_error() && !status.is_server_error() {
81        let content = resp.text().await?;
82        match content_type {
83            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
84            ContentType::Text => return Ok(content),
85            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `String`")))),
86        }
87    } else {
88        let content = resp.text().await?;
89        let entity: Option<UnsubscribeNotificationError> = serde_json::from_str(&content).ok();
90        Err(Error::ResponseError(ResponseContent { status, content, entity }))
91    }
92}
93
94pub async fn verify_email_channel(configuration: &configuration::Configuration, params: VerifyEmailChannelParams) -> Result<models::EmailChannelVerifyResponse, Error<VerifyEmailChannelError>> {
95
96    let uri_str = format!("{}/v1/public/notifications/channels/verify", configuration.base_path);
97    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
98
99    if let Some(ref param_value) = params.token {
100        req_builder = req_builder.query(&[("token", &param_value.to_string())]);
101    }
102    if let Some(ref user_agent) = configuration.user_agent {
103        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
104    }
105    req_builder = req_builder.json(&params.email_channel_verify_request);
106
107    let req = req_builder.build()?;
108    let resp = configuration.client.execute(req).await?;
109
110    let status = resp.status();
111    let content_type = resp
112        .headers()
113        .get("content-type")
114        .and_then(|v| v.to_str().ok())
115        .unwrap_or("application/octet-stream");
116    let content_type = super::ContentType::from(content_type);
117
118    if !status.is_client_error() && !status.is_server_error() {
119        let content = resp.text().await?;
120        match content_type {
121            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
122            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::EmailChannelVerifyResponse`"))),
123            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::EmailChannelVerifyResponse`")))),
124        }
125    } else {
126        let content = resp.text().await?;
127        let entity: Option<VerifyEmailChannelError> = serde_json::from_str(&content).ok();
128        Err(Error::ResponseError(ResponseContent { status, content, entity }))
129    }
130}
131