bitwarden_api_api/apis/
notifications_api.rs1use std::sync::Arc;
12
13use async_trait::async_trait;
14#[cfg(feature = "mockall")]
15use mockall::automock;
16use reqwest;
17use serde::{Deserialize, Serialize, de::Error as _};
18
19use super::{Error, configuration};
20use crate::{
21 apis::{AuthRequired, ContentType, ResponseContent},
22 models,
23};
24
25#[cfg_attr(feature = "mockall", automock)]
26#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
27#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
28pub trait NotificationsApi: Send + Sync {
29 async fn list<'a>(
31 &self,
32 read_status_filter: Option<bool>,
33 deleted_status_filter: Option<bool>,
34 continuation_token: Option<&'a str>,
35 page_size: Option<i32>,
36 ) -> Result<models::NotificationResponseModelListResponseModel, Error<ListError>>;
37
38 async fn mark_as_deleted<'a>(&self, id: uuid::Uuid) -> Result<(), Error<MarkAsDeletedError>>;
40
41 async fn mark_as_read<'a>(&self, id: uuid::Uuid) -> Result<(), Error<MarkAsReadError>>;
43}
44
45pub struct NotificationsApiClient {
46 configuration: Arc<configuration::Configuration>,
47}
48
49impl NotificationsApiClient {
50 pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
51 Self { configuration }
52 }
53}
54
55#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
56#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
57impl NotificationsApi for NotificationsApiClient {
58 async fn list<'a>(
59 &self,
60 read_status_filter: Option<bool>,
61 deleted_status_filter: Option<bool>,
62 continuation_token: Option<&'a str>,
63 page_size: Option<i32>,
64 ) -> Result<models::NotificationResponseModelListResponseModel, Error<ListError>> {
65 let local_var_configuration = &self.configuration;
66
67 let local_var_client = &local_var_configuration.client;
68
69 let local_var_uri_str = format!("{}/notifications", local_var_configuration.base_path);
70 let mut local_var_req_builder =
71 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
72
73 if let Some(ref param_value) = read_status_filter {
74 local_var_req_builder =
75 local_var_req_builder.query(&[("readStatusFilter", ¶m_value.to_string())]);
76 }
77 if let Some(ref param_value) = deleted_status_filter {
78 local_var_req_builder =
79 local_var_req_builder.query(&[("deletedStatusFilter", ¶m_value.to_string())]);
80 }
81 if let Some(ref param_value) = continuation_token {
82 local_var_req_builder =
83 local_var_req_builder.query(&[("continuationToken", ¶m_value.to_string())]);
84 }
85 if let Some(ref param_value) = page_size {
86 local_var_req_builder =
87 local_var_req_builder.query(&[("pageSize", ¶m_value.to_string())]);
88 }
89 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
90
91 let local_var_resp = local_var_req_builder.send().await?;
92
93 let local_var_status = local_var_resp.status();
94 let local_var_content_type = local_var_resp
95 .headers()
96 .get("content-type")
97 .and_then(|v| v.to_str().ok())
98 .unwrap_or("application/octet-stream");
99 let local_var_content_type = super::ContentType::from(local_var_content_type);
100 let local_var_content = local_var_resp.text().await?;
101
102 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
103 match local_var_content_type {
104 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
105 ContentType::Text => {
106 return Err(Error::from(serde_json::Error::custom(
107 "Received `text/plain` content type response that cannot be converted to `models::NotificationResponseModelListResponseModel`",
108 )));
109 }
110 ContentType::Unsupported(local_var_unknown_type) => {
111 return Err(Error::from(serde_json::Error::custom(format!(
112 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::NotificationResponseModelListResponseModel`"
113 ))));
114 }
115 }
116 } else {
117 let local_var_entity: Option<ListError> = serde_json::from_str(&local_var_content).ok();
118 let local_var_error = ResponseContent {
119 status: local_var_status,
120 content: local_var_content,
121 entity: local_var_entity,
122 };
123 Err(Error::ResponseError(local_var_error))
124 }
125 }
126
127 async fn mark_as_deleted<'a>(&self, id: uuid::Uuid) -> Result<(), Error<MarkAsDeletedError>> {
128 let local_var_configuration = &self.configuration;
129
130 let local_var_client = &local_var_configuration.client;
131
132 let local_var_uri_str = format!(
133 "{}/notifications/{id}/delete",
134 local_var_configuration.base_path,
135 id = id
136 );
137 let mut local_var_req_builder =
138 local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
139
140 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
141
142 let local_var_resp = local_var_req_builder.send().await?;
143
144 let local_var_status = local_var_resp.status();
145 let local_var_content = local_var_resp.text().await?;
146
147 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
148 Ok(())
149 } else {
150 let local_var_entity: Option<MarkAsDeletedError> =
151 serde_json::from_str(&local_var_content).ok();
152 let local_var_error = ResponseContent {
153 status: local_var_status,
154 content: local_var_content,
155 entity: local_var_entity,
156 };
157 Err(Error::ResponseError(local_var_error))
158 }
159 }
160
161 async fn mark_as_read<'a>(&self, id: uuid::Uuid) -> Result<(), Error<MarkAsReadError>> {
162 let local_var_configuration = &self.configuration;
163
164 let local_var_client = &local_var_configuration.client;
165
166 let local_var_uri_str = format!(
167 "{}/notifications/{id}/read",
168 local_var_configuration.base_path,
169 id = id
170 );
171 let mut local_var_req_builder =
172 local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
173
174 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
175
176 let local_var_resp = local_var_req_builder.send().await?;
177
178 let local_var_status = local_var_resp.status();
179 let local_var_content = local_var_resp.text().await?;
180
181 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
182 Ok(())
183 } else {
184 let local_var_entity: Option<MarkAsReadError> =
185 serde_json::from_str(&local_var_content).ok();
186 let local_var_error = ResponseContent {
187 status: local_var_status,
188 content: local_var_content,
189 entity: local_var_entity,
190 };
191 Err(Error::ResponseError(local_var_error))
192 }
193 }
194}
195
196#[derive(Debug, Clone, Serialize, Deserialize)]
198#[serde(untagged)]
199pub enum ListError {
200 UnknownValue(serde_json::Value),
201}
202#[derive(Debug, Clone, Serialize, Deserialize)]
204#[serde(untagged)]
205pub enum MarkAsDeletedError {
206 UnknownValue(serde_json::Value),
207}
208#[derive(Debug, Clone, Serialize, Deserialize)]
210#[serde(untagged)]
211pub enum MarkAsReadError {
212 UnknownValue(serde_json::Value),
213}