babelforce_manager_sdk/resources/
recordings.rs1use std::sync::Arc;
2
3use crate::error::{map_manager_err, ManagerError};
4use crate::gen::manager::apis::configuration::Configuration;
5use crate::gen::manager::apis::recording_api;
6use crate::gen::manager::models;
7use crate::http::{collect_all, fetch_page, Page};
8use crate::retry::{with_retry, RetryPolicy};
9
10pub struct RecordingsResource {
12 pub(crate) cfg: Arc<Configuration>,
13 pub(crate) retry: RetryPolicy,
14}
15
16impl RecordingsResource {
17 pub async fn list_all(&self) -> Result<Vec<models::Recording>, ManagerError> {
19 collect_all(&self.retry, map_manager_err, |page| async move {
20 let r = recording_api::list_recordings(self.cfg.as_ref(), Some(page), None).await?;
21 Ok((r.items, r.pagination.pages, r.pagination.current))
22 })
23 .await
24 }
25
26 pub async fn list_page(
28 &self,
29 page: i32,
30 per_page: Option<i32>,
31 ) -> Result<Page<models::Recording>, ManagerError> {
32 fetch_page(&self.retry, map_manager_err, || async move {
33 let r = recording_api::list_recordings(self.cfg.as_ref(), Some(page), per_page).await?;
34 Ok((
35 r.items,
36 r.pagination.pages,
37 r.pagination.current,
38 Some(r.pagination.total),
39 ))
40 })
41 .await
42 }
43
44 pub async fn start(
46 &self,
47 body: models::RecordingStartRequest,
48 ) -> Result<models::RecordingItemResponse, ManagerError> {
49 with_retry(&self.retry, false, || {
50 recording_api::start_recording(self.cfg.as_ref(), body.clone())
51 })
52 .await
53 .map_err(map_manager_err)
54 }
55
56 pub async fn get(&self, id: &str) -> Result<models::RecordingItemResponse, ManagerError> {
58 with_retry(&self.retry, true, || {
59 recording_api::get_recording(self.cfg.as_ref(), id)
60 })
61 .await
62 .map_err(map_manager_err)
63 }
64
65 pub async fn update(
67 &self,
68 id: &str,
69 body: models::RecordingUpdateBody,
70 ) -> Result<models::RecordingItemResponse, ManagerError> {
71 with_retry(&self.retry, false, || {
72 recording_api::update_recording(self.cfg.as_ref(), id, body.clone())
73 })
74 .await
75 .map_err(map_manager_err)
76 }
77
78 pub async fn delete(&self, id: &str) -> Result<(), ManagerError> {
80 with_retry(&self.retry, false, || {
81 recording_api::delete_recording(self.cfg.as_ref(), id)
82 })
83 .await
84 .map_err(map_manager_err)?;
85 Ok(())
86 }
87
88 pub async fn bulk_action(
90 &self,
91 action: &str,
92 ids: Vec<String>,
93 ) -> Result<models::BulkActionResponse, ManagerError> {
94 let ids = ids
95 .iter()
96 .map(|id| {
97 uuid::Uuid::parse_str(id)
98 .map_err(|e| ManagerError::InvalidArgument(format!("ids: {e}")))
99 })
100 .collect::<Result<Vec<_>, _>>()?;
101 let body = models::BulkIdsRequest { ids };
102 with_retry(&self.retry, false, || {
103 recording_api::bulk_recording_action(self.cfg.as_ref(), action, body.clone())
104 })
105 .await
106 .map_err(map_manager_err)
107 }
108
109 pub async fn get_flag(&self, id: &str) -> Result<models::RecordingItemResponse, ManagerError> {
111 with_retry(&self.retry, true, || {
112 recording_api::get_recording_flag(self.cfg.as_ref(), id)
113 })
114 .await
115 .map_err(map_manager_err)
116 }
117
118 pub async fn flag(&self, id: &str) -> Result<models::RecordingItemResponse, ManagerError> {
120 with_retry(&self.retry, false, || {
121 recording_api::flag_recording(self.cfg.as_ref(), id)
122 })
123 .await
124 .map_err(map_manager_err)
125 }
126
127 pub async fn unflag(&self, id: &str) -> Result<models::RecordingItemResponse, ManagerError> {
129 with_retry(&self.retry, false, || {
130 recording_api::unflag_recording(self.cfg.as_ref(), id)
131 })
132 .await
133 .map_err(map_manager_err)
134 }
135
136 pub async fn toggle_flag(
138 &self,
139 id: &str,
140 ) -> Result<models::RecordingItemResponse, ManagerError> {
141 with_retry(&self.retry, false, || {
142 recording_api::toggle_recording_flag(self.cfg.as_ref(), id)
143 })
144 .await
145 .map_err(map_manager_err)
146 }
147}