babelforce-manager-sdk 0.46.0

Rust SDK for the babelforce manager APIs — auth, user & agent management, call reporting, metrics, and task automations.
Documentation
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};
use crate::token::SharedCfg;

/// Expressions — `/api/v2/expressions`. The catalog of available expressions plus an evaluator.
pub struct ExpressionsResource {
    pub(crate) cfg: SharedCfg<Configuration>,
    pub(crate) retry: RetryPolicy,
}

impl ExpressionsResource {
    /// List the available expressions.
    pub async fn list(&self) -> Result<Vec<models::AvailableExpression>, ManagerError> {
        let cfg = self.cfg.get().await?;
        let cfg = cfg.as_ref();
        let resp = with_retry(&self.retry, true, || api::list_expressions(cfg))
            .await
            .map_err(map_manager_err)?;
        Ok(resp.items)
    }

    /// Evaluate an expression. `is_async` runs the evaluation asynchronously.
    pub async fn evaluate(
        &self,
        body: models::EvaluateExpression,
        is_async: bool,
    ) -> Result<models::EvaluateExpressionResponse, ManagerError> {
        let cfg = self.cfg.get().await?;
        let cfg = cfg.as_ref();
        with_retry(&self.retry, false, || {
            api::evaluate_expression(cfg, is_async, Some(body.clone()))
        })
        .await
        .map_err(map_manager_err)
    }
}