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::{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 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
90 local_var_req_builder = local_var_req_builder
91 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
92 }
93 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
94 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
95 };
96
97 let local_var_req = local_var_req_builder.build()?;
98 let local_var_resp = local_var_client.execute(local_var_req).await?;
99
100 let local_var_status = local_var_resp.status();
101 let local_var_content_type = local_var_resp
102 .headers()
103 .get("content-type")
104 .and_then(|v| v.to_str().ok())
105 .unwrap_or("application/octet-stream");
106 let local_var_content_type = super::ContentType::from(local_var_content_type);
107 let local_var_content = local_var_resp.text().await?;
108
109 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
110 match local_var_content_type {
111 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
112 ContentType::Text => {
113 return Err(Error::from(serde_json::Error::custom(
114 "Received `text/plain` content type response that cannot be converted to `models::NotificationResponseModelListResponseModel`",
115 )));
116 }
117 ContentType::Unsupported(local_var_unknown_type) => {
118 return Err(Error::from(serde_json::Error::custom(format!(
119 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::NotificationResponseModelListResponseModel`"
120 ))));
121 }
122 }
123 } else {
124 let local_var_entity: Option<ListError> = serde_json::from_str(&local_var_content).ok();
125 let local_var_error = ResponseContent {
126 status: local_var_status,
127 content: local_var_content,
128 entity: local_var_entity,
129 };
130 Err(Error::ResponseError(local_var_error))
131 }
132 }
133
134 async fn mark_as_deleted<'a>(&self, id: uuid::Uuid) -> Result<(), Error<MarkAsDeletedError>> {
135 let local_var_configuration = &self.configuration;
136
137 let local_var_client = &local_var_configuration.client;
138
139 let local_var_uri_str = format!(
140 "{}/notifications/{id}/delete",
141 local_var_configuration.base_path,
142 id = id
143 );
144 let mut local_var_req_builder =
145 local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
146
147 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
148 local_var_req_builder = local_var_req_builder
149 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
150 }
151 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
152 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
153 };
154
155 let local_var_req = local_var_req_builder.build()?;
156 let local_var_resp = local_var_client.execute(local_var_req).await?;
157
158 let local_var_status = local_var_resp.status();
159 let local_var_content = local_var_resp.text().await?;
160
161 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
162 Ok(())
163 } else {
164 let local_var_entity: Option<MarkAsDeletedError> =
165 serde_json::from_str(&local_var_content).ok();
166 let local_var_error = ResponseContent {
167 status: local_var_status,
168 content: local_var_content,
169 entity: local_var_entity,
170 };
171 Err(Error::ResponseError(local_var_error))
172 }
173 }
174
175 async fn mark_as_read<'a>(&self, id: uuid::Uuid) -> Result<(), Error<MarkAsReadError>> {
176 let local_var_configuration = &self.configuration;
177
178 let local_var_client = &local_var_configuration.client;
179
180 let local_var_uri_str = format!(
181 "{}/notifications/{id}/read",
182 local_var_configuration.base_path,
183 id = id
184 );
185 let mut local_var_req_builder =
186 local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
187
188 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
189 local_var_req_builder = local_var_req_builder
190 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
191 }
192 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
193 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
194 };
195
196 let local_var_req = local_var_req_builder.build()?;
197 let local_var_resp = local_var_client.execute(local_var_req).await?;
198
199 let local_var_status = local_var_resp.status();
200 let local_var_content = local_var_resp.text().await?;
201
202 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
203 Ok(())
204 } else {
205 let local_var_entity: Option<MarkAsReadError> =
206 serde_json::from_str(&local_var_content).ok();
207 let local_var_error = ResponseContent {
208 status: local_var_status,
209 content: local_var_content,
210 entity: local_var_entity,
211 };
212 Err(Error::ResponseError(local_var_error))
213 }
214 }
215}
216
217#[derive(Debug, Clone, Serialize, Deserialize)]
219#[serde(untagged)]
220pub enum ListError {
221 UnknownValue(serde_json::Value),
222}
223#[derive(Debug, Clone, Serialize, Deserialize)]
225#[serde(untagged)]
226pub enum MarkAsDeletedError {
227 UnknownValue(serde_json::Value),
228}
229#[derive(Debug, Clone, Serialize, Deserialize)]
231#[serde(untagged)]
232pub enum MarkAsReadError {
233 UnknownValue(serde_json::Value),
234}