babelforce_manager_sdk/resources/
sessions.rs1use crate::error::{map_manager_err, ManagerError};
2use crate::gen::manager::apis::configuration::Configuration;
3use crate::gen::manager::apis::manager_api as api;
4use crate::gen::manager::models;
5use crate::retry::{with_retry, RetryPolicy};
6use crate::token::SharedCfg;
7
8pub struct SessionsResource {
10 pub(crate) cfg: SharedCfg<Configuration>,
11 pub(crate) retry: RetryPolicy,
12}
13
14impl SessionsResource {
15 pub async fn create(&self) -> Result<models::SessionResponse, ManagerError> {
17 let cfg = self.cfg.get().await?;
18 let cfg = cfg.as_ref();
19 with_retry(&self.retry, false, || api::create_session(cfg))
20 .await
21 .map_err(map_manager_err)
22 }
23
24 pub async fn get(&self, id: &str) -> Result<models::SessionResponse, ManagerError> {
26 let cfg = self.cfg.get().await?;
27 let cfg = cfg.as_ref();
28 with_retry(&self.retry, true, || api::get_session_variables(cfg, id))
29 .await
30 .map_err(map_manager_err)
31 }
32
33 pub async fn update_variables(
35 &self,
36 id: &str,
37 variables: std::collections::HashMap<String, serde_json::Value>,
38 ) -> Result<models::SessionResponse, ManagerError> {
39 let cfg = self.cfg.get().await?;
40 let cfg = cfg.as_ref();
41 with_retry(&self.retry, false, || {
42 api::update_session_variables(cfg, id, Some(variables.clone()))
43 })
44 .await
45 .map_err(map_manager_err)
46 }
47}