babelforce-manager-sdk 0.42.3

Rust SDK for the babelforce manager APIs — auth, user & agent management, call reporting, metrics, and task automations.
Documentation
use std::sync::Arc;

use crate::error::{map_user_err, ManagerError};
use crate::gen::user::apis::configuration::Configuration;
use crate::gen::user::apis::user_api as api;
use crate::gen::user::models;
use crate::retry::{with_retry, RetryPolicy};

/// The authenticated principal — the current user, the accounts they can access, and self-service
/// password reset. Backed by `/api/v2/user` (the user spec).
pub struct MeResource {
    pub(crate) cfg: Arc<Configuration>,
    pub(crate) retry: RetryPolicy,
}

impl MeResource {
    /// Get the current user.
    pub async fn get(&self) -> Result<models::UserItemResponse, ManagerError> {
        with_retry(&self.retry, true, || api::get_user(self.cfg.as_ref()))
            .await
            .map_err(map_user_err)
    }

    /// Get the current user together with their account (customer) information.
    pub async fn customer(&self) -> Result<models::UserCustomerItemResponse, ManagerError> {
        with_retry(&self.retry, true, || {
            api::get_user_customer(self.cfg.as_ref())
        })
        .await
        .map_err(map_user_err)
    }

    /// List the accounts the current user can access.
    pub async fn accounts(&self) -> Result<Vec<models::Account>, ManagerError> {
        let resp = with_retry(&self.retry, true, || api::list_accounts(self.cfg.as_ref()))
            .await
            .map_err(map_user_err)?;
        Ok(resp.items)
    }

    /// Request a password-reset email for the current user.
    pub async fn reset_password(&self) -> Result<(), ManagerError> {
        with_retry(&self.retry, false, || {
            api::reset_password(self.cfg.as_ref())
        })
        .await
        .map_err(map_user_err)?;
        Ok(())
    }
}