babelforce-manager-sdk 0.42.1

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::events_api as api;
use crate::gen::manager::models;
use crate::retry::{with_retry, RetryPolicy};

/// Event definitions & custom events — `/api/v2/events`.
pub struct EventsResource {
    pub(crate) cfg: Arc<Configuration>,
    pub(crate) retry: RetryPolicy,
}

impl EventsResource {
    /// List the known events.
    pub async fn list(&self) -> Result<Vec<models::Event>, ManagerError> {
        let resp = with_retry(&self.retry, true, || {
            api::list_events(self.cfg.as_ref(), None)
        })
        .await
        .map_err(map_manager_err)?;
        Ok(resp.items)
    }

    /// Create a custom event.
    pub async fn create_custom(
        &self,
        body: models::CustomEventRequest,
    ) -> Result<models::EventItemResponse, ManagerError> {
        with_retry(&self.retry, false, || {
            api::create_custom_event(self.cfg.as_ref(), body.clone())
        })
        .await
        .map_err(map_manager_err)
    }

    /// Delete a custom event.
    pub async fn delete_custom(&self, id: &str) -> Result<(), ManagerError> {
        with_retry(&self.retry, false, || {
            api::delete_custom_event(self.cfg.as_ref(), id)
        })
        .await
        .map_err(map_manager_err)
    }
}