fizzy-sdk 0.2.4

Official Fizzy API client, generated from the Smithy model in spec/
Documentation
// Generated by fizzy-sdk-generator from openapi.json and behavior-model.json. DO NOT EDIT.

use crate::client::Scope;
use crate::error::Error;
use crate::generated::routes;
use crate::generated::types::*;
use crate::pagination::Page;

/// Optional query parameters for `GetNotificationTray`.
#[derive(Debug, Clone, Default, PartialEq)]
pub struct GetNotificationTrayParams {
    /// `include_read`.
    pub include_read: Option<bool>,
}

/// Optional query parameters for `ListNotifications`.
#[derive(Debug, Clone, Default, PartialEq)]
pub struct ListNotificationsParams {
    /// `read`.
    pub read: Option<bool>,
}

/// The `Notifications` operations.
pub struct NotificationsService<'a> {
    scope: Scope<'a>,
}

impl<'a> NotificationsService<'a> {
    pub(crate) fn new(scope: Scope<'a>) -> Self {
        Self { scope }
    }

    /// The client and account these operations send through.
    pub fn scope(&self) -> &Scope<'a> {
        &self.scope
    }

    /// `BulkReadNotifications` — `POST /{accountId}/notifications/bulk_reading.json`.
    ///
    /// Sent once and never resent.
    pub async fn bulk_read(&self, body: &BulkReadNotificationsRequestContent) -> Result<(), Error> {
        let mut operation = self
            .scope
            .operation(&routes::BULK_READ_NOTIFICATIONS, &[])?;
        operation.json(body)?;
        self.scope.client().send_unit(operation).await
    }

    /// `GetNotificationSettings` — `GET /{accountId}/notifications/settings.json`.
    ///
    /// Sent up to 3 times, backing off from 1000 ms, when the answer is 429, 500 or 503.
    pub async fn get_settings(&self) -> Result<NotificationSettings, Error> {
        let operation = self
            .scope
            .operation(&routes::GET_NOTIFICATION_SETTINGS, &[])?;
        self.scope.client().send(operation).await
    }

    /// `GetNotificationTray` — `GET /{accountId}/notifications/tray.json`.
    ///
    /// Sent up to 3 times, backing off from 1000 ms, when the answer is 429, 500 or 503.
    pub async fn get_tray(
        &self,
        params: &GetNotificationTrayParams,
    ) -> Result<Vec<Notification>, Error> {
        let mut operation = self.scope.operation(&routes::GET_NOTIFICATION_TRAY, &[])?;
        operation.query_optional("include_read", params.include_read.as_ref());
        self.scope.client().send(operation).await
    }

    /// `ListNotifications` — `GET /{accountId}/notifications.json`.
    ///
    /// Sent up to 3 times, backing off from 1000 ms, when the answer is 429, 500 or 503.
    ///
    /// Paginated: the answer is a page with `page` as its cursor, and the next one is read with `next_page`.
    pub async fn list(
        &self,
        params: &ListNotificationsParams,
    ) -> Result<Page<Vec<Notification>>, Error> {
        let mut operation = self.scope.operation(&routes::LIST_NOTIFICATIONS, &[])?;
        operation.query_optional("read", params.read.as_ref());
        self.scope.client().send_page(operation).await
    }

    /// `ReadNotification` — `POST /{accountId}/notifications/{notificationId}/reading.json`.
    ///
    /// Sent up to 3 times, backing off from 1000 ms, when the answer is 429, 500 or 503. Idempotent, so a resend is safe.
    pub async fn read(&self, notification_id: &str) -> Result<(), Error> {
        let mut operation = self
            .scope
            .operation(&routes::READ_NOTIFICATION, &[&notification_id])?;
        operation.resource_id(notification_id);
        self.scope.client().send_unit(operation).await
    }

    /// `UnreadNotification` — `DELETE /{accountId}/notifications/{notificationId}/reading.json`.
    ///
    /// Sent up to 3 times, backing off from 1000 ms, when the answer is 429, 500 or 503.
    pub async fn unread(&self, notification_id: &str) -> Result<(), Error> {
        let mut operation = self
            .scope
            .operation(&routes::UNREAD_NOTIFICATION, &[&notification_id])?;
        operation.resource_id(notification_id);
        self.scope.client().send_unit(operation).await
    }

    /// `UpdateNotificationSettings` — `PATCH /{accountId}/notifications/settings.json`.
    ///
    /// Sent up to 3 times, backing off from 1000 ms, when the answer is 429, 500 or 503.
    pub async fn update_settings(
        &self,
        body: &UpdateNotificationSettingsRequestContent,
    ) -> Result<(), Error> {
        let mut operation = self
            .scope
            .operation(&routes::UPDATE_NOTIFICATION_SETTINGS, &[])?;
        operation.json(body)?;
        self.scope.client().send_unit(operation).await
    }
}