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, metric_api};
use crate::gen::manager::models;
use crate::retry::{with_retry, RetryPolicy};

/// Metrics — `/api/v2/metrics`.
pub struct MetricsResource {
    pub(crate) cfg: Arc<Configuration>,
    pub(crate) retry: RetryPolicy,
}

impl MetricsResource {
    /// List the available metric ids.
    pub async fn list_ids(&self) -> Result<models::MetricIdItemsResponse, ManagerError> {
        with_retry(&self.retry, true, || {
            manager_api::list_metric_ids(self.cfg.as_ref())
        })
        .await
        .map_err(map_manager_err)
    }

    /// List all metric definitions.
    pub async fn definitions(&self) -> Result<models::MetricDefinitionListResponse, ManagerError> {
        with_retry(&self.retry, true, || {
            manager_api::get_all_metric_definitions(self.cfg.as_ref())
        })
        .await
        .map_err(map_manager_err)
    }

    /// Get a metric's current value by id.
    pub async fn get(&self, id: &str) -> Result<models::MetricResponse, ManagerError> {
        with_retry(&self.retry, true, || {
            manager_api::get_metric(self.cfg.as_ref(), id)
        })
        .await
        .map_err(map_manager_err)
    }

    /// Get a metric's definition by id.
    pub async fn describe(
        &self,
        id: &str,
    ) -> Result<models::MetricDefinitionItemResponse, ManagerError> {
        with_retry(&self.retry, true, || {
            metric_api::get_metric_definition(self.cfg.as_ref(), id)
        })
        .await
        .map_err(map_manager_err)
    }
}