babelforce-manager-sdk 0.42.2

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};

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

impl ExpressionsResource {
    /// List the available expressions.
    pub async fn list(&self) -> Result<Vec<models::AvailableExpression>, ManagerError> {
        let resp = with_retry(&self.retry, true, || {
            api::list_expressions(self.cfg.as_ref())
        })
        .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> {
        with_retry(&self.retry, false, || {
            api::evaluate_expression(self.cfg.as_ref(), is_async, Some(body.clone()))
        })
        .await
        .map_err(map_manager_err)
    }
}