agentcat_api/apis/
alerts_api.rs1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17#[derive(Clone, Debug)]
19pub struct UnsubscribeAlertGetParams {
20 pub token: Option<String>
21}
22
23#[derive(Clone, Debug)]
25pub struct UnsubscribeAlertPostParams {
26 pub token: Option<String>
27}
28
29
30#[derive(Debug, Clone, Serialize, Deserialize)]
32#[serde(untagged)]
33pub enum UnsubscribeAlertGetError {
34 Status400(String),
35 Status401(models::Error),
36 Status403(models::Error),
37 UnknownValue(serde_json::Value),
38}
39
40#[derive(Debug, Clone, Serialize, Deserialize)]
42#[serde(untagged)]
43pub enum UnsubscribeAlertPostError {
44 Status400(String),
45 Status401(models::Error),
46 Status403(models::Error),
47 UnknownValue(serde_json::Value),
48}
49
50
51pub async fn unsubscribe_alert_get(configuration: &configuration::Configuration, params: UnsubscribeAlertGetParams) -> Result<String, Error<UnsubscribeAlertGetError>> {
53
54 let uri_str = format!("{}/v1/public/alerts/unsubscribe", configuration.base_path);
55 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
56
57 if let Some(ref param_value) = params.token {
58 req_builder = req_builder.query(&[("token", ¶m_value.to_string())]);
59 }
60 if let Some(ref user_agent) = configuration.user_agent {
61 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
62 }
63
64 let req = req_builder.build()?;
65 let resp = configuration.client.execute(req).await?;
66
67 let status = resp.status();
68 let content_type = resp
69 .headers()
70 .get("content-type")
71 .and_then(|v| v.to_str().ok())
72 .unwrap_or("application/octet-stream");
73 let content_type = super::ContentType::from(content_type);
74
75 if !status.is_client_error() && !status.is_server_error() {
76 let content = resp.text().await?;
77 match content_type {
78 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
79 ContentType::Text => return Ok(content),
80 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`")))),
81 }
82 } else {
83 let content = resp.text().await?;
84 let entity: Option<UnsubscribeAlertGetError> = serde_json::from_str(&content).ok();
85 Err(Error::ResponseError(ResponseContent { status, content, entity }))
86 }
87}
88
89pub async fn unsubscribe_alert_post(configuration: &configuration::Configuration, params: UnsubscribeAlertPostParams) -> Result<String, Error<UnsubscribeAlertPostError>> {
91
92 let uri_str = format!("{}/v1/public/alerts/unsubscribe", configuration.base_path);
93 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
94
95 if let Some(ref param_value) = params.token {
96 req_builder = req_builder.query(&[("token", ¶m_value.to_string())]);
97 }
98 if let Some(ref user_agent) = configuration.user_agent {
99 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
100 }
101
102 let req = req_builder.build()?;
103 let resp = configuration.client.execute(req).await?;
104
105 let status = resp.status();
106 let content_type = resp
107 .headers()
108 .get("content-type")
109 .and_then(|v| v.to_str().ok())
110 .unwrap_or("application/octet-stream");
111 let content_type = super::ContentType::from(content_type);
112
113 if !status.is_client_error() && !status.is_server_error() {
114 let content = resp.text().await?;
115 match content_type {
116 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
117 ContentType::Text => return Ok(content),
118 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`")))),
119 }
120 } else {
121 let content = resp.text().await?;
122 let entity: Option<UnsubscribeAlertPostError> = serde_json::from_str(&content).ok();
123 Err(Error::ResponseError(ResponseContent { status, content, entity }))
124 }
125}
126