Skip to main content

box_open_sdk/managers/
hub_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 [`HubCollaborationsManager::list`].
7#[derive(Clone, Debug, Default)]
8pub struct HubCollaborationsListOptions {
9    pub marker: Option<String>,
10    pub limit: Option<i64>,
11}
12
13/// Async paginator over [`HubCollaborationsManager::list`], yielding one `crate::models::schemas::HubCollaboration`
14/// per item across pages (FR-7.3).
15pub struct HubCollaborationsListPaginator {
16    manager: HubCollaborationsManager,
17    hub_id: String,
18    options: HubCollaborationsListOptions,
19    buffer: std::vec::IntoIter<crate::models::schemas::HubCollaboration>,
20    done: bool,
21}
22
23impl HubCollaborationsListPaginator {
24    /// The next item, advancing pages as needed; `None` at the end.
25    /// An error is yielded once, then iteration stops.
26    pub async fn next(
27        &mut self,
28    ) -> Option<Result<crate::models::schemas::HubCollaboration, Error>> {
29        loop {
30            if let Some(item) = self.buffer.next() {
31                return Some(Ok(item));
32            }
33            if self.done {
34                return None;
35            }
36            let page = match self
37                .manager
38                .list_page(self.hub_id.clone(), Some(self.options.clone()))
39                .await
40            {
41                Ok(page) => page,
42                Err(err) => {
43                    self.done = true;
44                    return Some(Err(err));
45                }
46            };
47            self.buffer = page.entries.unwrap_or_default().into_iter();
48            match page.next_marker.flatten() {
49                Some(cursor) if !cursor.is_empty() => self.options.marker = Some(cursor),
50                _ => self.done = true,
51            }
52        }
53    }
54}
55
56/// Operations for the "hub_collaborations" API area.
57pub struct HubCollaborationsManager {
58    session: std::sync::Arc<runtime::Client>,
59}
60
61impl HubCollaborationsManager {
62    pub(crate) fn new(session: std::sync::Arc<runtime::Client>) -> Self {
63        Self { session }
64    }
65
66    async fn list_page(
67        &self,
68        hub_id: String,
69        opts: Option<HubCollaborationsListOptions>,
70    ) -> Result<crate::models::schemas::HubCollaborations, Error> {
71        let mut url = self.session.base_url("api");
72        url.push_str("/hub_collaborations");
73        let mut req = self.session.new_request("GET", &url);
74        req = runtime::with_query(req, "hub_id", &hub_id);
75        let opts = opts.unwrap_or_default();
76        if let Some(value) = opts.marker {
77            req = runtime::with_query(req, "marker", &value);
78        }
79        if let Some(value) = opts.limit {
80            req = runtime::with_query(req, "limit", &value.to_string());
81        }
82        req = runtime::with_header(req, "box-version", "2025.0");
83        let resp = self.session.fetch(req).await?;
84        let data = runtime::response_bytes(&resp)?;
85        Ok(serde_json::from_slice(&data)?)
86    }
87
88    /// Iterate every `crate::models::schemas::HubCollaboration` across pages, threading the cursor.
89    pub fn list(
90        &self,
91        hub_id: String,
92        opts: Option<HubCollaborationsListOptions>,
93    ) -> HubCollaborationsListPaginator {
94        HubCollaborationsListPaginator {
95            manager: HubCollaborationsManager::new(self.session.clone()),
96            hub_id,
97            options: opts.unwrap_or_default(),
98            buffer: Vec::new().into_iter(),
99            done: false,
100        }
101    }
102
103    pub async fn create(
104        &self,
105        body: crate::models::schemas::HubCollaborationCreateRequest,
106    ) -> Result<crate::models::schemas::HubCollaboration, Error> {
107        let mut url = self.session.base_url("api");
108        url.push_str("/hub_collaborations");
109        let mut req = self.session.new_request("POST", &url);
110        req = runtime::with_header(req, "box-version", "2025.0");
111        let payload = serde_json::to_vec(&body)?;
112        req = runtime::with_json_body(req, &payload);
113        let resp = self.session.fetch(req).await?;
114        let data = runtime::response_bytes(&resp)?;
115        Ok(serde_json::from_slice(&data)?)
116    }
117
118    pub async fn get(
119        &self,
120        hub_collaboration_id: String,
121    ) -> Result<crate::models::schemas::HubCollaboration, Error> {
122        let mut url = self.session.base_url("api");
123        url.push_str("/hub_collaborations");
124        url.push('/');
125        let seg = path_escape(&hub_collaboration_id);
126        url.push_str(&seg);
127        let mut req = self.session.new_request("GET", &url);
128        req = runtime::with_header(req, "box-version", "2025.0");
129        let resp = self.session.fetch(req).await?;
130        let data = runtime::response_bytes(&resp)?;
131        Ok(serde_json::from_slice(&data)?)
132    }
133
134    pub async fn update(
135        &self,
136        hub_collaboration_id: String,
137        body: crate::models::schemas::HubCollaborationUpdateRequest,
138    ) -> Result<crate::models::schemas::HubCollaboration, Error> {
139        let mut url = self.session.base_url("api");
140        url.push_str("/hub_collaborations");
141        url.push('/');
142        let seg = path_escape(&hub_collaboration_id);
143        url.push_str(&seg);
144        let mut req = self.session.new_request("PUT", &url);
145        req = runtime::with_header(req, "box-version", "2025.0");
146        let payload = serde_json::to_vec(&body)?;
147        req = runtime::with_json_body(req, &payload);
148        let resp = self.session.fetch(req).await?;
149        let data = runtime::response_bytes(&resp)?;
150        Ok(serde_json::from_slice(&data)?)
151    }
152
153    pub async fn delete(&self, hub_collaboration_id: String) -> Result<(), Error> {
154        let mut url = self.session.base_url("api");
155        url.push_str("/hub_collaborations");
156        url.push('/');
157        let seg = path_escape(&hub_collaboration_id);
158        url.push_str(&seg);
159        let mut req = self.session.new_request("DELETE", &url);
160        req = runtime::with_header(req, "box-version", "2025.0");
161        let _ = self.session.fetch(req).await?;
162        Ok(())
163    }
164}