Skip to main content

fizzy_sdk/generated/services/
notifications.rs

1// Generated by fizzy-sdk-generator from openapi.json and behavior-model.json. DO NOT EDIT.
2
3use crate::client::Scope;
4use crate::error::Error;
5use crate::generated::routes;
6use crate::generated::types::*;
7use crate::pagination::Page;
8
9/// Optional query parameters for `GetNotificationTray`.
10#[derive(Debug, Clone, Default, PartialEq)]
11pub struct GetNotificationTrayParams {
12    /// `include_read`.
13    pub include_read: Option<bool>,
14}
15
16/// Optional query parameters for `ListNotifications`.
17#[derive(Debug, Clone, Default, PartialEq)]
18pub struct ListNotificationsParams {
19    /// `read`.
20    pub read: Option<bool>,
21}
22
23/// The `Notifications` operations.
24pub struct NotificationsService<'a> {
25    scope: Scope<'a>,
26}
27
28impl<'a> NotificationsService<'a> {
29    pub(crate) fn new(scope: Scope<'a>) -> Self {
30        Self { scope }
31    }
32
33    /// The client and account these operations send through.
34    pub fn scope(&self) -> &Scope<'a> {
35        &self.scope
36    }
37
38    /// `BulkReadNotifications` — `POST /{accountId}/notifications/bulk_reading.json`.
39    ///
40    /// Sent once and never resent.
41    pub async fn bulk_read(&self, body: &BulkReadNotificationsRequestContent) -> Result<(), Error> {
42        let mut operation = self
43            .scope
44            .operation(&routes::BULK_READ_NOTIFICATIONS, &[])?;
45        operation.json(body)?;
46        self.scope.client().send_unit(operation).await
47    }
48
49    /// `GetNotificationSettings` — `GET /{accountId}/notifications/settings.json`.
50    ///
51    /// Sent up to 3 times, backing off from 1000 ms, when the answer is 429, 500 or 503.
52    pub async fn get_settings(&self) -> Result<NotificationSettings, Error> {
53        let operation = self
54            .scope
55            .operation(&routes::GET_NOTIFICATION_SETTINGS, &[])?;
56        self.scope.client().send(operation).await
57    }
58
59    /// `GetNotificationTray` — `GET /{accountId}/notifications/tray.json`.
60    ///
61    /// Sent up to 3 times, backing off from 1000 ms, when the answer is 429, 500 or 503.
62    pub async fn get_tray(
63        &self,
64        params: &GetNotificationTrayParams,
65    ) -> Result<Vec<Notification>, Error> {
66        let mut operation = self.scope.operation(&routes::GET_NOTIFICATION_TRAY, &[])?;
67        operation.query_optional("include_read", params.include_read.as_ref());
68        self.scope.client().send(operation).await
69    }
70
71    /// `ListNotifications` — `GET /{accountId}/notifications.json`.
72    ///
73    /// Sent up to 3 times, backing off from 1000 ms, when the answer is 429, 500 or 503.
74    ///
75    /// Paginated: the answer is a page with `page` as its cursor, and the next one is read with `next_page`.
76    pub async fn list(
77        &self,
78        params: &ListNotificationsParams,
79    ) -> Result<Page<Vec<Notification>>, Error> {
80        let mut operation = self.scope.operation(&routes::LIST_NOTIFICATIONS, &[])?;
81        operation.query_optional("read", params.read.as_ref());
82        self.scope.client().send_page(operation).await
83    }
84
85    /// `ReadNotification` — `POST /{accountId}/notifications/{notificationId}/reading.json`.
86    ///
87    /// Sent up to 3 times, backing off from 1000 ms, when the answer is 429, 500 or 503. Idempotent, so a resend is safe.
88    pub async fn read(&self, notification_id: &str) -> Result<(), Error> {
89        let mut operation = self
90            .scope
91            .operation(&routes::READ_NOTIFICATION, &[&notification_id])?;
92        operation.resource_id(notification_id);
93        self.scope.client().send_unit(operation).await
94    }
95
96    /// `UnreadNotification` — `DELETE /{accountId}/notifications/{notificationId}/reading.json`.
97    ///
98    /// Sent up to 3 times, backing off from 1000 ms, when the answer is 429, 500 or 503.
99    pub async fn unread(&self, notification_id: &str) -> Result<(), Error> {
100        let mut operation = self
101            .scope
102            .operation(&routes::UNREAD_NOTIFICATION, &[&notification_id])?;
103        operation.resource_id(notification_id);
104        self.scope.client().send_unit(operation).await
105    }
106
107    /// `UpdateNotificationSettings` — `PATCH /{accountId}/notifications/settings.json`.
108    ///
109    /// Sent up to 3 times, backing off from 1000 ms, when the answer is 429, 500 or 503.
110    pub async fn update_settings(
111        &self,
112        body: &UpdateNotificationSettingsRequestContent,
113    ) -> Result<(), Error> {
114        let mut operation = self
115            .scope
116            .operation(&routes::UPDATE_NOTIFICATION_SETTINGS, &[])?;
117        operation.json(body)?;
118        self.scope.client().send_unit(operation).await
119    }
120}