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_manager_err, ManagerError};
use crate::gen::manager::apis::configuration::Configuration;
use crate::gen::manager::apis::manager_api as api;
use crate::gen::manager::models;
use crate::retry::{with_retry, RetryPolicy};

/// System & reference data — health checks, server time, timezones, tags, templates.
pub struct SystemResource {
    pub(crate) cfg: Arc<Configuration>,
    pub(crate) retry: RetryPolicy,
}

impl SystemResource {
    /// Echo back the request — `/api/v2/echo`.
    pub async fn echo(&self) -> Result<models::GenericItemResponse, ManagerError> {
        with_retry(&self.retry, true, || api::echo(self.cfg.as_ref()))
            .await
            .map_err(map_manager_err)
    }

    /// Liveness ping — `/api/v2/ping`.
    pub async fn ping(&self) -> Result<models::GenericItemResponse, ManagerError> {
        with_retry(&self.retry, true, || api::ping(self.cfg.as_ref()))
            .await
            .map_err(map_manager_err)
    }

    /// API status — `/api/v2/status`.
    pub async fn api_status(&self) -> Result<models::GenericItemResponse, ManagerError> {
        with_retry(&self.retry, true, || api::get_api_status(self.cfg.as_ref()))
            .await
            .map_err(map_manager_err)
    }

    /// Current server time — `/api/v2/data/time`.
    pub async fn server_time(&self) -> Result<models::GenericItemResponse, ManagerError> {
        with_retry(&self.retry, true, || {
            api::get_server_time(self.cfg.as_ref())
        })
        .await
        .map_err(map_manager_err)
    }

    /// List timezones, optionally filtered by `q` and capped by `max` — `/api/v2/data/timezones`.
    pub async fn timezones(
        &self,
        q: Option<&str>,
        max: Option<i32>,
    ) -> Result<models::ObjectListResponse, ManagerError> {
        with_retry(&self.retry, true, || {
            api::list_timezones(self.cfg.as_ref(), q, max)
        })
        .await
        .map_err(map_manager_err)
    }

    /// Fetch the push notification token — `/api/v2/push-token`.
    pub async fn push_token(&self) -> Result<models::GenericItemResponse, ManagerError> {
        with_retry(&self.retry, true, || api::get_push_token(self.cfg.as_ref()))
            .await
            .map_err(map_manager_err)
    }

    /// List all tags — `/api/v2/tags`.
    pub async fn tags(&self) -> Result<models::ObjectListResponse, ManagerError> {
        with_retry(&self.retry, true, || api::list_tags(self.cfg.as_ref()))
            .await
            .map_err(map_manager_err)
    }

    /// List tags in a category — `/api/v2/tags/{category}`.
    pub async fn tags_by_category(
        &self,
        category: &str,
    ) -> Result<models::ObjectListResponse, ManagerError> {
        with_retry(&self.retry, true, || {
            api::list_tags_by_category(self.cfg.as_ref(), category)
        })
        .await
        .map_err(map_manager_err)
    }

    /// Export templates of a given type — `/api/v2/templates/export/{type}`.
    pub async fn export_templates(
        &self,
        r#type: &str,
    ) -> Result<std::collections::HashMap<String, serde_json::Value>, ManagerError> {
        with_retry(&self.retry, true, || {
            api::export_templates(self.cfg.as_ref(), r#type)
        })
        .await
        .map_err(map_manager_err)
    }
}