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/// The `Notifications` operations.
17pub struct NotificationsService<'a> {
18    scope: Scope<'a>,
19}
20
21impl<'a> NotificationsService<'a> {
22    pub(crate) fn new(scope: Scope<'a>) -> Self {
23        Self { scope }
24    }
25
26    /// The client and account these operations send through.
27    pub fn scope(&self) -> &Scope<'a> {
28        &self.scope
29    }
30
31    /// `BulkReadNotifications` — `POST /{accountId}/notifications/bulk_reading.json`.
32    ///
33    /// Sent once and never resent.
34    pub async fn bulk_read(&self, body: &BulkReadNotificationsRequestContent) -> Result<(), Error> {
35        let mut operation = self
36            .scope
37            .operation(&routes::BULK_READ_NOTIFICATIONS, &[])?;
38        operation.json(body)?;
39        self.scope.client().send_unit(operation).await
40    }
41
42    /// `GetNotificationSettings` — `GET /{accountId}/notifications/settings.json`.
43    ///
44    /// Sent up to 3 times, backing off from 1000 ms, when the answer is 429, 500 or 503.
45    pub async fn get_settings(&self) -> Result<NotificationSettings, Error> {
46        let operation = self
47            .scope
48            .operation(&routes::GET_NOTIFICATION_SETTINGS, &[])?;
49        self.scope.client().send(operation).await
50    }
51
52    /// `GetNotificationTray` — `GET /{accountId}/notifications/tray.json`.
53    ///
54    /// Sent up to 3 times, backing off from 1000 ms, when the answer is 429, 500 or 503.
55    pub async fn get_tray(
56        &self,
57        params: &GetNotificationTrayParams,
58    ) -> Result<Vec<Notification>, Error> {
59        let mut operation = self.scope.operation(&routes::GET_NOTIFICATION_TRAY, &[])?;
60        operation.query_optional("include_read", params.include_read.as_ref());
61        self.scope.client().send(operation).await
62    }
63
64    /// `ListNotifications` — `GET /{accountId}/notifications.json`.
65    ///
66    /// Sent up to 3 times, backing off from 1000 ms, when the answer is 429, 500 or 503.
67    ///
68    /// Paginated: the answer is a page with `page` as its cursor, and the next one is read with `next_page`.
69    pub async fn list(&self) -> Result<Page<Vec<Notification>>, Error> {
70        let operation = self.scope.operation(&routes::LIST_NOTIFICATIONS, &[])?;
71        self.scope.client().send_page(operation).await
72    }
73
74    /// `ReadNotification` — `POST /{accountId}/notifications/{notificationId}/reading.json`.
75    ///
76    /// Sent up to 3 times, backing off from 1000 ms, when the answer is 429, 500 or 503. Idempotent, so a resend is safe.
77    pub async fn read(&self, notification_id: &str) -> Result<(), Error> {
78        let mut operation = self
79            .scope
80            .operation(&routes::READ_NOTIFICATION, &[&notification_id])?;
81        operation.resource_id(notification_id);
82        self.scope.client().send_unit(operation).await
83    }
84
85    /// `UnreadNotification` — `DELETE /{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.
88    pub async fn unread(&self, notification_id: &str) -> Result<(), Error> {
89        let mut operation = self
90            .scope
91            .operation(&routes::UNREAD_NOTIFICATION, &[&notification_id])?;
92        operation.resource_id(notification_id);
93        self.scope.client().send_unit(operation).await
94    }
95
96    /// `UpdateNotificationSettings` — `PATCH /{accountId}/notifications/settings.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 update_settings(
100        &self,
101        body: &UpdateNotificationSettingsRequestContent,
102    ) -> Result<(), Error> {
103        let mut operation = self
104            .scope
105            .operation(&routes::UPDATE_NOTIFICATION_SETTINGS, &[])?;
106        operation.json(body)?;
107        self.scope.client().send_unit(operation).await
108    }
109}