1use crate::internal::path_escape;
4use crate::runtime::{self, Error};
5
6#[derive(Clone, Debug, Default)]
8pub struct IntegrationMappingsListSlackOptions {
9 pub marker: Option<String>,
10 pub limit: Option<i64>,
11 pub partner_item_type: Option<crate::models::schemas::IntegrationMappingPartnerItemSlackType>,
12 pub partner_item_id: Option<String>,
13 pub box_item_id: Option<String>,
14 pub box_item_type: Option<crate::models::schemas::FolderType>,
15 pub is_manually_created: Option<bool>,
16}
17
18#[derive(Clone, Debug, Default)]
20pub struct IntegrationMappingsListTeamsOptions {
21 pub partner_item_type: Option<crate::models::schemas::IntegrationMappingPartnerItemTeamsType>,
22 pub partner_item_id: Option<String>,
23 pub box_item_id: Option<String>,
24 pub box_item_type: Option<crate::models::schemas::FolderType>,
25}
26
27pub struct IntegrationMappingsListSlackPaginator {
30 manager: IntegrationMappingsManager,
31 options: IntegrationMappingsListSlackOptions,
32 buffer: std::vec::IntoIter<crate::models::schemas::IntegrationMapping>,
33 done: bool,
34}
35
36impl IntegrationMappingsListSlackPaginator {
37 pub async fn next(
40 &mut self,
41 ) -> Option<Result<crate::models::schemas::IntegrationMapping, Error>> {
42 loop {
43 if let Some(item) = self.buffer.next() {
44 return Some(Ok(item));
45 }
46 if self.done {
47 return None;
48 }
49 let page = match self
50 .manager
51 .list_slack_page(Some(self.options.clone()))
52 .await
53 {
54 Ok(page) => page,
55 Err(err) => {
56 self.done = true;
57 return Some(Err(err));
58 }
59 };
60 self.buffer = page.entries.unwrap_or_default().into_iter();
61 match page.next_marker.flatten() {
62 Some(cursor) if !cursor.is_empty() => self.options.marker = Some(cursor),
63 _ => self.done = true,
64 }
65 }
66 }
67}
68
69pub struct IntegrationMappingsManager {
71 session: std::sync::Arc<runtime::Client>,
72}
73
74impl IntegrationMappingsManager {
75 pub(crate) fn new(session: std::sync::Arc<runtime::Client>) -> Self {
76 Self { session }
77 }
78
79 async fn list_slack_page(
80 &self,
81 opts: Option<IntegrationMappingsListSlackOptions>,
82 ) -> Result<crate::models::schemas::IntegrationMappings, Error> {
83 let mut url = self.session.base_url("api");
84 url.push_str("/integration_mappings");
85 url.push_str("/slack");
86 let mut req = self.session.new_request("GET", &url);
87 let opts = opts.unwrap_or_default();
88 if let Some(value) = opts.marker {
89 req = runtime::with_query(req, "marker", &value);
90 }
91 if let Some(value) = opts.limit {
92 req = runtime::with_query(req, "limit", &value.to_string());
93 }
94 if let Some(value) = opts.partner_item_type {
95 req = runtime::with_query(req, "partner_item_type", &value.0);
96 }
97 if let Some(value) = opts.partner_item_id {
98 req = runtime::with_query(req, "partner_item_id", &value);
99 }
100 if let Some(value) = opts.box_item_id {
101 req = runtime::with_query(req, "box_item_id", &value);
102 }
103 if let Some(value) = opts.box_item_type {
104 req = runtime::with_query(req, "box_item_type", &value.0);
105 }
106 if let Some(value) = opts.is_manually_created {
107 req = runtime::with_query(req, "is_manually_created", &value.to_string());
108 }
109 let resp = self.session.fetch(req).await?;
110 let data = runtime::response_bytes(&resp)?;
111 Ok(serde_json::from_slice(&data)?)
112 }
113
114 pub fn list_slack(
116 &self,
117 opts: Option<IntegrationMappingsListSlackOptions>,
118 ) -> IntegrationMappingsListSlackPaginator {
119 IntegrationMappingsListSlackPaginator {
120 manager: IntegrationMappingsManager::new(self.session.clone()),
121 options: opts.unwrap_or_default(),
122 buffer: Vec::new().into_iter(),
123 done: false,
124 }
125 }
126
127 pub async fn create_slack(
128 &self,
129 body: crate::models::schemas::IntegrationMappingSlackCreateRequest,
130 ) -> Result<crate::models::schemas::IntegrationMapping, Error> {
131 let mut url = self.session.base_url("api");
132 url.push_str("/integration_mappings");
133 url.push_str("/slack");
134 let mut req = self.session.new_request("POST", &url);
135 let payload = serde_json::to_vec(&body)?;
136 req = runtime::with_json_body(req, &payload);
137 let resp = self.session.fetch(req).await?;
138 let data = runtime::response_bytes(&resp)?;
139 Ok(serde_json::from_slice(&data)?)
140 }
141
142 pub async fn update_slack(
143 &self,
144 integration_mapping_id: String,
145 body: crate::models::schemas::UpdateSlackRequest,
146 ) -> Result<crate::models::schemas::IntegrationMapping, Error> {
147 let mut url = self.session.base_url("api");
148 url.push_str("/integration_mappings");
149 url.push_str("/slack");
150 url.push('/');
151 let seg = path_escape(&integration_mapping_id);
152 url.push_str(&seg);
153 let mut req = self.session.new_request("PUT", &url);
154 let payload = serde_json::to_vec(&body)?;
155 req = runtime::with_json_body(req, &payload);
156 let resp = self.session.fetch(req).await?;
157 let data = runtime::response_bytes(&resp)?;
158 Ok(serde_json::from_slice(&data)?)
159 }
160
161 pub async fn delete_slack(&self, integration_mapping_id: String) -> Result<(), Error> {
162 let mut url = self.session.base_url("api");
163 url.push_str("/integration_mappings");
164 url.push_str("/slack");
165 url.push('/');
166 let seg = path_escape(&integration_mapping_id);
167 url.push_str(&seg);
168 let req = self.session.new_request("DELETE", &url);
169 let _ = self.session.fetch(req).await?;
170 Ok(())
171 }
172
173 pub async fn list_teams(
174 &self,
175 opts: Option<IntegrationMappingsListTeamsOptions>,
176 ) -> Result<crate::models::schemas::IntegrationMappingsTeams, Error> {
177 let mut url = self.session.base_url("api");
178 url.push_str("/integration_mappings");
179 url.push_str("/teams");
180 let mut req = self.session.new_request("GET", &url);
181 let opts = opts.unwrap_or_default();
182 if let Some(value) = opts.partner_item_type {
183 req = runtime::with_query(req, "partner_item_type", &value.0);
184 }
185 if let Some(value) = opts.partner_item_id {
186 req = runtime::with_query(req, "partner_item_id", &value);
187 }
188 if let Some(value) = opts.box_item_id {
189 req = runtime::with_query(req, "box_item_id", &value);
190 }
191 if let Some(value) = opts.box_item_type {
192 req = runtime::with_query(req, "box_item_type", &value.0);
193 }
194 let resp = self.session.fetch(req).await?;
195 let data = runtime::response_bytes(&resp)?;
196 Ok(serde_json::from_slice(&data)?)
197 }
198
199 pub async fn create_teams(
200 &self,
201 body: crate::models::schemas::IntegrationMappingTeamsCreateRequest,
202 ) -> Result<crate::models::schemas::IntegrationMappingTeams, Error> {
203 let mut url = self.session.base_url("api");
204 url.push_str("/integration_mappings");
205 url.push_str("/teams");
206 let mut req = self.session.new_request("POST", &url);
207 let payload = serde_json::to_vec(&body)?;
208 req = runtime::with_json_body(req, &payload);
209 let resp = self.session.fetch(req).await?;
210 let data = runtime::response_bytes(&resp)?;
211 Ok(serde_json::from_slice(&data)?)
212 }
213
214 pub async fn update_team(
215 &self,
216 integration_mapping_id: String,
217 body: crate::models::schemas::UpdateTeamRequest,
218 ) -> Result<crate::models::schemas::IntegrationMappingTeams, Error> {
219 let mut url = self.session.base_url("api");
220 url.push_str("/integration_mappings");
221 url.push_str("/teams");
222 url.push('/');
223 let seg = path_escape(&integration_mapping_id);
224 url.push_str(&seg);
225 let mut req = self.session.new_request("PUT", &url);
226 let payload = serde_json::to_vec(&body)?;
227 req = runtime::with_json_body(req, &payload);
228 let resp = self.session.fetch(req).await?;
229 let data = runtime::response_bytes(&resp)?;
230 Ok(serde_json::from_slice(&data)?)
231 }
232
233 pub async fn delete_team(&self, integration_mapping_id: String) -> Result<(), Error> {
234 let mut url = self.session.base_url("api");
235 url.push_str("/integration_mappings");
236 url.push_str("/teams");
237 url.push('/');
238 let seg = path_escape(&integration_mapping_id);
239 url.push_str(&seg);
240 let req = self.session.new_request("DELETE", &url);
241 let _ = self.session.fetch(req).await?;
242 Ok(())
243 }
244}