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;

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

impl<'a> UsersService<'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
    }

    /// `ConfirmEmailAddressChange` — `POST /{accountId}/users/{userId}/email_addresses/{emailAddressToken}/confirmation.json`.
    ///
    /// Sent once and never resent.
    pub async fn confirm_email_address_change(
        &self,
        user_id: &str,
        email_address_token: &str,
    ) -> Result<(), Error> {
        let mut operation = self.scope.operation(
            &routes::CONFIRM_EMAIL_ADDRESS_CHANGE,
            &[&user_id, &email_address_token],
        )?;
        operation.resource_id(user_id);
        self.scope.client().send_unit(operation).await
    }

    /// `CreatePushSubscription` — `POST /{accountId}/users/{userId}/push_subscriptions.json`.
    ///
    /// Sent once and never resent.
    pub async fn create_push_subscription(
        &self,
        user_id: &str,
        body: &CreatePushSubscriptionRequestContent,
    ) -> Result<(), Error> {
        let mut operation = self
            .scope
            .operation(&routes::CREATE_PUSH_SUBSCRIPTION, &[&user_id])?;
        operation.resource_id(user_id);
        operation.json(body)?;
        self.scope.client().send_unit(operation).await
    }

    /// `CreateUserDataExport` — `POST /{accountId}/users/{userId}/data_exports.json`.
    ///
    /// Sent once and never resent.
    pub async fn create_user_data_export(&self, user_id: &str) -> Result<DataExport, Error> {
        let mut operation = self
            .scope
            .operation(&routes::CREATE_USER_DATA_EXPORT, &[&user_id])?;
        operation.resource_id(user_id);
        self.scope.client().send(operation).await
    }

    /// `DeactivateUser` — `DELETE /{accountId}/users/{userId}`.
    ///
    /// Sent up to 3 times, backing off from 1000 ms, when the answer is 429, 500 or 503.
    pub async fn deactivate(&self, user_id: &str) -> Result<(), Error> {
        let mut operation = self
            .scope
            .operation(&routes::DEACTIVATE_USER, &[&user_id])?;
        operation.resource_id(user_id);
        self.scope.client().send_unit(operation).await
    }

    /// `DeleteUserAvatar` — `DELETE /{accountId}/users/{userId}/avatar`.
    ///
    /// Sent up to 3 times, backing off from 1000 ms, when the answer is 429, 500 or 503.
    pub async fn delete_avatar(&self, user_id: &str) -> Result<(), Error> {
        let mut operation = self
            .scope
            .operation(&routes::DELETE_USER_AVATAR, &[&user_id])?;
        operation.resource_id(user_id);
        self.scope.client().send_unit(operation).await
    }

    /// `DeletePushSubscription` — `DELETE /{accountId}/users/{userId}/push_subscriptions/{pushSubscriptionId}`.
    ///
    /// Sent up to 3 times, backing off from 1000 ms, when the answer is 429, 500 or 503.
    pub async fn delete_push_subscription(
        &self,
        user_id: &str,
        push_subscription_id: &str,
    ) -> Result<(), Error> {
        let mut operation = self.scope.operation(
            &routes::DELETE_PUSH_SUBSCRIPTION,
            &[&user_id, &push_subscription_id],
        )?;
        operation.resource_id(push_subscription_id);
        self.scope.client().send_unit(operation).await
    }

    /// `GetUser` — `GET /{accountId}/users/{userId}`.
    ///
    /// Sent up to 3 times, backing off from 1000 ms, when the answer is 429, 500 or 503.
    pub async fn get(&self, user_id: &str) -> Result<User, Error> {
        let mut operation = self.scope.operation(&routes::GET_USER, &[&user_id])?;
        operation.resource_id(user_id);
        self.scope.client().send(operation).await
    }

    /// `GetUserDataExport` — `GET /{accountId}/users/{userId}/data_exports/{exportId}`.
    ///
    /// Sent up to 3 times, backing off from 1000 ms, when the answer is 429, 500 or 503.
    pub async fn get_user_data_export(
        &self,
        user_id: &str,
        export_id: &str,
    ) -> Result<DataExport, Error> {
        let mut operation = self
            .scope
            .operation(&routes::GET_USER_DATA_EXPORT, &[&user_id, &export_id])?;
        operation.resource_id(export_id);
        self.scope.client().send(operation).await
    }

    /// `ListUsers` — `GET /{accountId}/users.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) -> Result<Page<Vec<User>>, Error> {
        let operation = self.scope.operation(&routes::LIST_USERS, &[])?;
        self.scope.client().send_page(operation).await
    }

    /// `RequestEmailAddressChange` — `POST /{accountId}/users/{userId}/email_addresses.json`.
    ///
    /// Sent once and never resent.
    pub async fn request_email_address_change(
        &self,
        user_id: &str,
        body: &RequestEmailAddressChangeRequestContent,
    ) -> Result<(), Error> {
        let mut operation = self
            .scope
            .operation(&routes::REQUEST_EMAIL_ADDRESS_CHANGE, &[&user_id])?;
        operation.resource_id(user_id);
        operation.json(body)?;
        self.scope.client().send_unit(operation).await
    }

    /// `UpdateUser` — `PATCH /{accountId}/users/{userId}`.
    ///
    /// Sent up to 3 times, backing off from 1000 ms, when the answer is 429, 500 or 503.
    pub async fn update(
        &self,
        user_id: &str,
        body: &UpdateUserRequestContent,
    ) -> Result<User, Error> {
        let mut operation = self.scope.operation(&routes::UPDATE_USER, &[&user_id])?;
        operation.resource_id(user_id);
        operation.json(body)?;
        self.scope.client().send(operation).await
    }

    /// `UpdateUserRole` — `PATCH /{accountId}/users/{userId}/role.json`.
    ///
    /// Sent up to 3 times, backing off from 1000 ms, when the answer is 429, 500 or 503.
    pub async fn update_role(
        &self,
        user_id: &str,
        body: &UpdateUserRoleRequestContent,
    ) -> Result<(), Error> {
        let mut operation = self
            .scope
            .operation(&routes::UPDATE_USER_ROLE, &[&user_id])?;
        operation.resource_id(user_id);
        operation.json(body)?;
        self.scope.client().send_unit(operation).await
    }
}