babelforce_manager_sdk/resources/
events.rs1use std::sync::Arc;
2
3use crate::error::{map_manager_err, ManagerError};
4use crate::gen::manager::apis::configuration::Configuration;
5use crate::gen::manager::apis::events_api as api;
6use crate::gen::manager::models;
7use crate::retry::{with_retry, RetryPolicy};
8
9pub struct EventsResource {
11 pub(crate) cfg: Arc<Configuration>,
12 pub(crate) retry: RetryPolicy,
13}
14
15impl EventsResource {
16 pub async fn list(&self) -> Result<Vec<models::Event>, ManagerError> {
18 let resp = with_retry(&self.retry, true, || {
19 api::list_events(self.cfg.as_ref(), None)
20 })
21 .await
22 .map_err(map_manager_err)?;
23 Ok(resp.items)
24 }
25
26 pub async fn create_custom(
28 &self,
29 body: models::CustomEventRequest,
30 ) -> Result<models::EventItemResponse, ManagerError> {
31 with_retry(&self.retry, false, || {
32 api::create_custom_event(self.cfg.as_ref(), body.clone())
33 })
34 .await
35 .map_err(map_manager_err)
36 }
37
38 pub async fn delete_custom(&self, id: &str) -> Result<(), ManagerError> {
40 with_retry(&self.retry, false, || {
41 api::delete_custom_event(self.cfg.as_ref(), id)
42 })
43 .await
44 .map_err(map_manager_err)
45 }
46}