Skip to main content

box_open_sdk/managers/
list_collaborations.rs

1// Code generated by box-gantry. DO NOT EDIT.
2
3use crate::internal::path_escape;
4use crate::runtime::{self, Error};
5
6/// Optional parameters for [`ListCollaborationsManager::list_file_collaborations`].
7#[derive(Clone, Debug, Default)]
8pub struct ListCollaborationsListFileCollaborationsOptions {
9    pub fields: Option<Vec<String>>,
10    pub limit: Option<i64>,
11    pub marker: Option<String>,
12}
13
14/// Optional parameters for [`ListCollaborationsManager::list_folder_collaborations`].
15#[derive(Clone, Debug, Default)]
16pub struct ListCollaborationsListFolderCollaborationsOptions {
17    pub fields: Option<Vec<String>>,
18    pub limit: Option<i64>,
19    pub marker: Option<String>,
20}
21
22/// Optional parameters for [`ListCollaborationsManager::list_collaborations`].
23#[derive(Clone, Debug, Default)]
24pub struct ListCollaborationsListCollaborationsOptions {
25    pub fields: Option<Vec<String>>,
26    pub offset: Option<i64>,
27    pub limit: Option<i64>,
28}
29
30/// Optional parameters for [`ListCollaborationsManager::list_group_collaborations`].
31#[derive(Clone, Debug, Default)]
32pub struct ListCollaborationsListGroupCollaborationsOptions {
33    pub limit: Option<i64>,
34    pub offset: Option<i64>,
35}
36
37/// Async paginator over [`ListCollaborationsManager::list_file_collaborations`], yielding one `crate::models::schemas::Collaboration`
38/// per item across pages (FR-7.3).
39pub struct ListCollaborationsListFileCollaborationsPaginator {
40    manager: ListCollaborationsManager,
41    file_id: String,
42    options: ListCollaborationsListFileCollaborationsOptions,
43    buffer: std::vec::IntoIter<crate::models::schemas::Collaboration>,
44    done: bool,
45}
46
47impl ListCollaborationsListFileCollaborationsPaginator {
48    /// The next item, advancing pages as needed; `None` at the end.
49    /// An error is yielded once, then iteration stops.
50    pub async fn next(&mut self) -> Option<Result<crate::models::schemas::Collaboration, Error>> {
51        loop {
52            if let Some(item) = self.buffer.next() {
53                return Some(Ok(item));
54            }
55            if self.done {
56                return None;
57            }
58            let page = match self
59                .manager
60                .list_file_collaborations_page(self.file_id.clone(), Some(self.options.clone()))
61                .await
62            {
63                Ok(page) => page,
64                Err(err) => {
65                    self.done = true;
66                    return Some(Err(err));
67                }
68            };
69            self.buffer = page.entries.unwrap_or_default().into_iter();
70            match page.next_marker.flatten() {
71                Some(cursor) if !cursor.is_empty() => self.options.marker = Some(cursor),
72                _ => self.done = true,
73            }
74        }
75    }
76}
77
78/// Async paginator over [`ListCollaborationsManager::list_folder_collaborations`], yielding one `crate::models::schemas::Collaboration`
79/// per item across pages (FR-7.3).
80pub struct ListCollaborationsListFolderCollaborationsPaginator {
81    manager: ListCollaborationsManager,
82    folder_id: String,
83    options: ListCollaborationsListFolderCollaborationsOptions,
84    buffer: std::vec::IntoIter<crate::models::schemas::Collaboration>,
85    done: bool,
86}
87
88impl ListCollaborationsListFolderCollaborationsPaginator {
89    /// The next item, advancing pages as needed; `None` at the end.
90    /// An error is yielded once, then iteration stops.
91    pub async fn next(&mut self) -> Option<Result<crate::models::schemas::Collaboration, Error>> {
92        loop {
93            if let Some(item) = self.buffer.next() {
94                return Some(Ok(item));
95            }
96            if self.done {
97                return None;
98            }
99            let page = match self
100                .manager
101                .list_folder_collaborations_page(self.folder_id.clone(), Some(self.options.clone()))
102                .await
103            {
104                Ok(page) => page,
105                Err(err) => {
106                    self.done = true;
107                    return Some(Err(err));
108                }
109            };
110            self.buffer = page.entries.unwrap_or_default().into_iter();
111            match page.next_marker.flatten() {
112                Some(cursor) if !cursor.is_empty() => self.options.marker = Some(cursor),
113                _ => self.done = true,
114            }
115        }
116    }
117}
118
119/// Async paginator over [`ListCollaborationsManager::list_collaborations`], yielding one `crate::models::schemas::Collaboration`
120/// per item across pages (FR-7.3).
121pub struct ListCollaborationsListCollaborationsPaginator {
122    manager: ListCollaborationsManager,
123    status: crate::models::schemas::GetCollaborationsStatus,
124    options: ListCollaborationsListCollaborationsOptions,
125    buffer: std::vec::IntoIter<crate::models::schemas::Collaboration>,
126    done: bool,
127}
128
129impl ListCollaborationsListCollaborationsPaginator {
130    /// The next item, advancing pages as needed; `None` at the end.
131    /// An error is yielded once, then iteration stops.
132    pub async fn next(&mut self) -> Option<Result<crate::models::schemas::Collaboration, Error>> {
133        loop {
134            if let Some(item) = self.buffer.next() {
135                return Some(Ok(item));
136            }
137            if self.done {
138                return None;
139            }
140            let page = match self
141                .manager
142                .list_collaborations_page(self.status.clone(), Some(self.options.clone()))
143                .await
144            {
145                Ok(page) => page,
146                Err(err) => {
147                    self.done = true;
148                    return Some(Err(err));
149                }
150            };
151            let items = page.entries.unwrap_or_default();
152            if items.is_empty() {
153                self.done = true;
154            } else {
155                let next = self.options.offset.unwrap_or(0) + items.len() as i64;
156                self.options.offset = Some(next);
157            }
158            self.buffer = items.into_iter();
159        }
160    }
161}
162
163/// Async paginator over [`ListCollaborationsManager::list_group_collaborations`], yielding one `crate::models::schemas::Collaboration`
164/// per item across pages (FR-7.3).
165pub struct ListCollaborationsListGroupCollaborationsPaginator {
166    manager: ListCollaborationsManager,
167    group_id: String,
168    options: ListCollaborationsListGroupCollaborationsOptions,
169    buffer: std::vec::IntoIter<crate::models::schemas::Collaboration>,
170    done: bool,
171}
172
173impl ListCollaborationsListGroupCollaborationsPaginator {
174    /// The next item, advancing pages as needed; `None` at the end.
175    /// An error is yielded once, then iteration stops.
176    pub async fn next(&mut self) -> Option<Result<crate::models::schemas::Collaboration, Error>> {
177        loop {
178            if let Some(item) = self.buffer.next() {
179                return Some(Ok(item));
180            }
181            if self.done {
182                return None;
183            }
184            let page = match self
185                .manager
186                .list_group_collaborations_page(self.group_id.clone(), Some(self.options.clone()))
187                .await
188            {
189                Ok(page) => page,
190                Err(err) => {
191                    self.done = true;
192                    return Some(Err(err));
193                }
194            };
195            let items = page.entries.unwrap_or_default();
196            if items.is_empty() {
197                self.done = true;
198            } else {
199                let next = self.options.offset.unwrap_or(0) + items.len() as i64;
200                self.options.offset = Some(next);
201            }
202            self.buffer = items.into_iter();
203        }
204    }
205}
206
207/// Operations for the "list_collaborations" API area.
208pub struct ListCollaborationsManager {
209    session: std::sync::Arc<runtime::Client>,
210}
211
212impl ListCollaborationsManager {
213    pub(crate) fn new(session: std::sync::Arc<runtime::Client>) -> Self {
214        Self { session }
215    }
216
217    async fn list_file_collaborations_page(
218        &self,
219        file_id: String,
220        opts: Option<ListCollaborationsListFileCollaborationsOptions>,
221    ) -> Result<crate::models::schemas::Collaborations, Error> {
222        let mut url = self.session.base_url("api");
223        url.push_str("/files");
224        url.push('/');
225        let seg = path_escape(&file_id);
226        url.push_str(&seg);
227        url.push_str("/collaborations");
228        let mut req = self.session.new_request("GET", &url);
229        let opts = opts.unwrap_or_default();
230        if let Some(value) = opts.fields {
231            req = runtime::with_query(req, "fields", &value.join(","));
232        }
233        if let Some(value) = opts.limit {
234            req = runtime::with_query(req, "limit", &value.to_string());
235        }
236        if let Some(value) = opts.marker {
237            req = runtime::with_query(req, "marker", &value);
238        }
239        let resp = self.session.fetch(req).await?;
240        let data = runtime::response_bytes(&resp)?;
241        Ok(serde_json::from_slice(&data)?)
242    }
243
244    /// Iterate every `crate::models::schemas::Collaboration` across pages, threading the cursor.
245    pub fn list_file_collaborations(
246        &self,
247        file_id: String,
248        opts: Option<ListCollaborationsListFileCollaborationsOptions>,
249    ) -> ListCollaborationsListFileCollaborationsPaginator {
250        ListCollaborationsListFileCollaborationsPaginator {
251            manager: ListCollaborationsManager::new(self.session.clone()),
252            file_id,
253            options: opts.unwrap_or_default(),
254            buffer: Vec::new().into_iter(),
255            done: false,
256        }
257    }
258
259    async fn list_folder_collaborations_page(
260        &self,
261        folder_id: String,
262        opts: Option<ListCollaborationsListFolderCollaborationsOptions>,
263    ) -> Result<crate::models::schemas::Collaborations, Error> {
264        let mut url = self.session.base_url("api");
265        url.push_str("/folders");
266        url.push('/');
267        let seg = path_escape(&folder_id);
268        url.push_str(&seg);
269        url.push_str("/collaborations");
270        let mut req = self.session.new_request("GET", &url);
271        let opts = opts.unwrap_or_default();
272        if let Some(value) = opts.fields {
273            req = runtime::with_query(req, "fields", &value.join(","));
274        }
275        if let Some(value) = opts.limit {
276            req = runtime::with_query(req, "limit", &value.to_string());
277        }
278        if let Some(value) = opts.marker {
279            req = runtime::with_query(req, "marker", &value);
280        }
281        let resp = self.session.fetch(req).await?;
282        let data = runtime::response_bytes(&resp)?;
283        Ok(serde_json::from_slice(&data)?)
284    }
285
286    /// Iterate every `crate::models::schemas::Collaboration` across pages, threading the cursor.
287    pub fn list_folder_collaborations(
288        &self,
289        folder_id: String,
290        opts: Option<ListCollaborationsListFolderCollaborationsOptions>,
291    ) -> ListCollaborationsListFolderCollaborationsPaginator {
292        ListCollaborationsListFolderCollaborationsPaginator {
293            manager: ListCollaborationsManager::new(self.session.clone()),
294            folder_id,
295            options: opts.unwrap_or_default(),
296            buffer: Vec::new().into_iter(),
297            done: false,
298        }
299    }
300
301    async fn list_collaborations_page(
302        &self,
303        status: crate::models::schemas::GetCollaborationsStatus,
304        opts: Option<ListCollaborationsListCollaborationsOptions>,
305    ) -> Result<crate::models::schemas::CollaborationsOffsetPaginated, Error> {
306        let mut url = self.session.base_url("api");
307        url.push_str("/collaborations");
308        let mut req = self.session.new_request("GET", &url);
309        req = runtime::with_query(req, "status", &status.0);
310        let opts = opts.unwrap_or_default();
311        if let Some(value) = opts.fields {
312            req = runtime::with_query(req, "fields", &value.join(","));
313        }
314        if let Some(value) = opts.offset {
315            req = runtime::with_query(req, "offset", &value.to_string());
316        }
317        if let Some(value) = opts.limit {
318            req = runtime::with_query(req, "limit", &value.to_string());
319        }
320        let resp = self.session.fetch(req).await?;
321        let data = runtime::response_bytes(&resp)?;
322        Ok(serde_json::from_slice(&data)?)
323    }
324
325    /// Iterate every `crate::models::schemas::Collaboration` across pages, threading the cursor.
326    pub fn list_collaborations(
327        &self,
328        status: crate::models::schemas::GetCollaborationsStatus,
329        opts: Option<ListCollaborationsListCollaborationsOptions>,
330    ) -> ListCollaborationsListCollaborationsPaginator {
331        ListCollaborationsListCollaborationsPaginator {
332            manager: ListCollaborationsManager::new(self.session.clone()),
333            status,
334            options: opts.unwrap_or_default(),
335            buffer: Vec::new().into_iter(),
336            done: false,
337        }
338    }
339
340    async fn list_group_collaborations_page(
341        &self,
342        group_id: String,
343        opts: Option<ListCollaborationsListGroupCollaborationsOptions>,
344    ) -> Result<crate::models::schemas::CollaborationsOffsetPaginated, Error> {
345        let mut url = self.session.base_url("api");
346        url.push_str("/groups");
347        url.push('/');
348        let seg = path_escape(&group_id);
349        url.push_str(&seg);
350        url.push_str("/collaborations");
351        let mut req = self.session.new_request("GET", &url);
352        let opts = opts.unwrap_or_default();
353        if let Some(value) = opts.limit {
354            req = runtime::with_query(req, "limit", &value.to_string());
355        }
356        if let Some(value) = opts.offset {
357            req = runtime::with_query(req, "offset", &value.to_string());
358        }
359        let resp = self.session.fetch(req).await?;
360        let data = runtime::response_bytes(&resp)?;
361        Ok(serde_json::from_slice(&data)?)
362    }
363
364    /// Iterate every `crate::models::schemas::Collaboration` across pages, threading the cursor.
365    pub fn list_group_collaborations(
366        &self,
367        group_id: String,
368        opts: Option<ListCollaborationsListGroupCollaborationsOptions>,
369    ) -> ListCollaborationsListGroupCollaborationsPaginator {
370        ListCollaborationsListGroupCollaborationsPaginator {
371            manager: ListCollaborationsManager::new(self.session.clone()),
372            group_id,
373            options: opts.unwrap_or_default(),
374            buffer: Vec::new().into_iter(),
375            done: false,
376        }
377    }
378}