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;
pub struct ExpressionsResource {
pub(crate) cfg: SharedCfg<Configuration>,
pub(crate) retry: RetryPolicy,
}
impl ExpressionsResource {
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)
}
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)
}
}