bitwarden_api_api/apis/
notifications_api.rs

1/*
2 * Bitwarden Internal API
3 *
4 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5 *
6 * The version of the OpenAPI document: latest
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use 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    /// GET /notifications
30    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    /// PATCH /notifications/{id}/delete
39    async fn mark_as_deleted<'a>(&self, id: uuid::Uuid) -> Result<(), Error<MarkAsDeletedError>>;
40
41    /// PATCH /notifications/{id}/read
42    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", &param_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", &param_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", &param_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", &param_value.to_string())]);
88        }
89        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
90            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
91        };
92        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
93
94        let local_var_req = local_var_req_builder.build()?;
95        let local_var_resp = local_var_client.execute(local_var_req).await?;
96
97        let local_var_status = local_var_resp.status();
98        let local_var_content_type = local_var_resp
99            .headers()
100            .get("content-type")
101            .and_then(|v| v.to_str().ok())
102            .unwrap_or("application/octet-stream");
103        let local_var_content_type = super::ContentType::from(local_var_content_type);
104        let local_var_content = local_var_resp.text().await?;
105
106        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
107            match local_var_content_type {
108                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
109                ContentType::Text => {
110                    return Err(Error::from(serde_json::Error::custom(
111                        "Received `text/plain` content type response that cannot be converted to `models::NotificationResponseModelListResponseModel`",
112                    )));
113                }
114                ContentType::Unsupported(local_var_unknown_type) => {
115                    return Err(Error::from(serde_json::Error::custom(format!(
116                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::NotificationResponseModelListResponseModel`"
117                    ))));
118                }
119            }
120        } else {
121            let local_var_entity: Option<ListError> = serde_json::from_str(&local_var_content).ok();
122            let local_var_error = ResponseContent {
123                status: local_var_status,
124                content: local_var_content,
125                entity: local_var_entity,
126            };
127            Err(Error::ResponseError(local_var_error))
128        }
129    }
130
131    async fn mark_as_deleted<'a>(&self, id: uuid::Uuid) -> Result<(), Error<MarkAsDeletedError>> {
132        let local_var_configuration = &self.configuration;
133
134        let local_var_client = &local_var_configuration.client;
135
136        let local_var_uri_str = format!(
137            "{}/notifications/{id}/delete",
138            local_var_configuration.base_path,
139            id = id
140        );
141        let mut local_var_req_builder =
142            local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
143
144        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
145            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
146        };
147        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
148
149        let local_var_req = local_var_req_builder.build()?;
150        let local_var_resp = local_var_client.execute(local_var_req).await?;
151
152        let local_var_status = local_var_resp.status();
153        let local_var_content = local_var_resp.text().await?;
154
155        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
156            Ok(())
157        } else {
158            let local_var_entity: Option<MarkAsDeletedError> =
159                serde_json::from_str(&local_var_content).ok();
160            let local_var_error = ResponseContent {
161                status: local_var_status,
162                content: local_var_content,
163                entity: local_var_entity,
164            };
165            Err(Error::ResponseError(local_var_error))
166        }
167    }
168
169    async fn mark_as_read<'a>(&self, id: uuid::Uuid) -> Result<(), Error<MarkAsReadError>> {
170        let local_var_configuration = &self.configuration;
171
172        let local_var_client = &local_var_configuration.client;
173
174        let local_var_uri_str = format!(
175            "{}/notifications/{id}/read",
176            local_var_configuration.base_path,
177            id = id
178        );
179        let mut local_var_req_builder =
180            local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
181
182        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
183            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
184        };
185        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
186
187        let local_var_req = local_var_req_builder.build()?;
188        let local_var_resp = local_var_client.execute(local_var_req).await?;
189
190        let local_var_status = local_var_resp.status();
191        let local_var_content = local_var_resp.text().await?;
192
193        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
194            Ok(())
195        } else {
196            let local_var_entity: Option<MarkAsReadError> =
197                serde_json::from_str(&local_var_content).ok();
198            let local_var_error = ResponseContent {
199                status: local_var_status,
200                content: local_var_content,
201                entity: local_var_entity,
202            };
203            Err(Error::ResponseError(local_var_error))
204        }
205    }
206}
207
208/// struct for typed errors of method [`NotificationsApi::list`]
209#[derive(Debug, Clone, Serialize, Deserialize)]
210#[serde(untagged)]
211pub enum ListError {
212    UnknownValue(serde_json::Value),
213}
214/// struct for typed errors of method [`NotificationsApi::mark_as_deleted`]
215#[derive(Debug, Clone, Serialize, Deserialize)]
216#[serde(untagged)]
217pub enum MarkAsDeletedError {
218    UnknownValue(serde_json::Value),
219}
220/// struct for typed errors of method [`NotificationsApi::mark_as_read`]
221#[derive(Debug, Clone, Serialize, Deserialize)]
222#[serde(untagged)]
223pub enum MarkAsReadError {
224    UnknownValue(serde_json::Value),
225}