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 reqwest;
12use serde::{de::Error as _, Deserialize, Serialize};
13
14use super::{configuration, ContentType, Error};
15use crate::{apis::ResponseContent, models};
16
17/// struct for typed errors of method [`notifications_get`]
18#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(untagged)]
20pub enum NotificationsGetError {
21    UnknownValue(serde_json::Value),
22}
23
24/// struct for typed errors of method [`notifications_id_delete_patch`]
25#[derive(Debug, Clone, Serialize, Deserialize)]
26#[serde(untagged)]
27pub enum NotificationsIdDeletePatchError {
28    UnknownValue(serde_json::Value),
29}
30
31/// struct for typed errors of method [`notifications_id_read_patch`]
32#[derive(Debug, Clone, Serialize, Deserialize)]
33#[serde(untagged)]
34pub enum NotificationsIdReadPatchError {
35    UnknownValue(serde_json::Value),
36}
37
38pub async fn notifications_get(
39    configuration: &configuration::Configuration,
40    read_status_filter: Option<bool>,
41    deleted_status_filter: Option<bool>,
42    continuation_token: Option<&str>,
43    page_size: Option<i32>,
44) -> Result<models::NotificationResponseModelListResponseModel, Error<NotificationsGetError>> {
45    // add a prefix to parameters to efficiently prevent name collisions
46    let p_read_status_filter = read_status_filter;
47    let p_deleted_status_filter = deleted_status_filter;
48    let p_continuation_token = continuation_token;
49    let p_page_size = page_size;
50
51    let uri_str = format!("{}/notifications", configuration.base_path);
52    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
53
54    if let Some(ref param_value) = p_read_status_filter {
55        req_builder = req_builder.query(&[("readStatusFilter", &param_value.to_string())]);
56    }
57    if let Some(ref param_value) = p_deleted_status_filter {
58        req_builder = req_builder.query(&[("deletedStatusFilter", &param_value.to_string())]);
59    }
60    if let Some(ref param_value) = p_continuation_token {
61        req_builder = req_builder.query(&[("continuationToken", &param_value.to_string())]);
62    }
63    if let Some(ref param_value) = p_page_size {
64        req_builder = req_builder.query(&[("pageSize", &param_value.to_string())]);
65    }
66    if let Some(ref user_agent) = configuration.user_agent {
67        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
68    }
69    if let Some(ref token) = configuration.oauth_access_token {
70        req_builder = req_builder.bearer_auth(token.to_owned());
71    };
72
73    let req = req_builder.build()?;
74    let resp = configuration.client.execute(req).await?;
75
76    let status = resp.status();
77    let content_type = resp
78        .headers()
79        .get("content-type")
80        .and_then(|v| v.to_str().ok())
81        .unwrap_or("application/octet-stream");
82    let content_type = super::ContentType::from(content_type);
83
84    if !status.is_client_error() && !status.is_server_error() {
85        let content = resp.text().await?;
86        match content_type {
87            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
88            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::NotificationResponseModelListResponseModel`"))),
89            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::NotificationResponseModelListResponseModel`")))),
90        }
91    } else {
92        let content = resp.text().await?;
93        let entity: Option<NotificationsGetError> = serde_json::from_str(&content).ok();
94        Err(Error::ResponseError(ResponseContent {
95            status,
96            content,
97            entity,
98        }))
99    }
100}
101
102pub async fn notifications_id_delete_patch(
103    configuration: &configuration::Configuration,
104    id: uuid::Uuid,
105) -> Result<(), Error<NotificationsIdDeletePatchError>> {
106    // add a prefix to parameters to efficiently prevent name collisions
107    let p_id = id;
108
109    let uri_str = format!(
110        "{}/notifications/{id}/delete",
111        configuration.base_path,
112        id = crate::apis::urlencode(p_id.to_string())
113    );
114    let mut req_builder = configuration
115        .client
116        .request(reqwest::Method::PATCH, &uri_str);
117
118    if let Some(ref user_agent) = configuration.user_agent {
119        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
120    }
121    if let Some(ref token) = configuration.oauth_access_token {
122        req_builder = req_builder.bearer_auth(token.to_owned());
123    };
124
125    let req = req_builder.build()?;
126    let resp = configuration.client.execute(req).await?;
127
128    let status = resp.status();
129
130    if !status.is_client_error() && !status.is_server_error() {
131        Ok(())
132    } else {
133        let content = resp.text().await?;
134        let entity: Option<NotificationsIdDeletePatchError> = serde_json::from_str(&content).ok();
135        Err(Error::ResponseError(ResponseContent {
136            status,
137            content,
138            entity,
139        }))
140    }
141}
142
143pub async fn notifications_id_read_patch(
144    configuration: &configuration::Configuration,
145    id: uuid::Uuid,
146) -> Result<(), Error<NotificationsIdReadPatchError>> {
147    // add a prefix to parameters to efficiently prevent name collisions
148    let p_id = id;
149
150    let uri_str = format!(
151        "{}/notifications/{id}/read",
152        configuration.base_path,
153        id = crate::apis::urlencode(p_id.to_string())
154    );
155    let mut req_builder = configuration
156        .client
157        .request(reqwest::Method::PATCH, &uri_str);
158
159    if let Some(ref user_agent) = configuration.user_agent {
160        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
161    }
162    if let Some(ref token) = configuration.oauth_access_token {
163        req_builder = req_builder.bearer_auth(token.to_owned());
164    };
165
166    let req = req_builder.build()?;
167    let resp = configuration.client.execute(req).await?;
168
169    let status = resp.status();
170
171    if !status.is_client_error() && !status.is_server_error() {
172        Ok(())
173    } else {
174        let content = resp.text().await?;
175        let entity: Option<NotificationsIdReadPatchError> = serde_json::from_str(&content).ok();
176        Err(Error::ResponseError(ResponseContent {
177            status,
178            content,
179            entity,
180        }))
181    }
182}