Skip to main content

babelforce_manager_sdk/resources/
expressions.rs

1use std::sync::Arc;
2
3use crate::error::{map_manager_err, ManagerError};
4use crate::gen::manager::apis::configuration::Configuration;
5use crate::gen::manager::apis::manager_api as api;
6use crate::gen::manager::models;
7use crate::retry::{with_retry, RetryPolicy};
8
9/// Expressions — `/api/v2/expressions`. The catalog of available expressions plus an evaluator.
10pub struct ExpressionsResource {
11    pub(crate) cfg: Arc<Configuration>,
12    pub(crate) retry: RetryPolicy,
13}
14
15impl ExpressionsResource {
16    /// List the available expressions.
17    pub async fn list(&self) -> Result<Vec<models::AvailableExpression>, ManagerError> {
18        let resp = with_retry(&self.retry, true, || {
19            api::list_expressions(self.cfg.as_ref())
20        })
21        .await
22        .map_err(map_manager_err)?;
23        Ok(resp.items)
24    }
25
26    /// Evaluate an expression. `is_async` runs the evaluation asynchronously.
27    pub async fn evaluate(
28        &self,
29        body: models::EvaluateExpression,
30        is_async: bool,
31    ) -> Result<models::EvaluateExpressionResponse, ManagerError> {
32        with_retry(&self.retry, false, || {
33            api::evaluate_expression(self.cfg.as_ref(), is_async, Some(body.clone()))
34        })
35        .await
36        .map_err(map_manager_err)
37    }
38}