zoom_api/
roles.rs

1use crate::Client;
2use crate::ClientResult;
3
4pub struct Roles {
5    pub client: Client,
6}
7
8impl Roles {
9    #[doc(hidden)]
10    pub fn new(client: Client) -> Self {
11        Roles { client }
12    }
13
14    /**
15     * List roles.
16     *
17     * This function performs a `GET` to the `/roles` endpoint.
18     *
19     * List [roles](https://support.zoom.us/hc/en-us/articles/115001078646-Role-Based-Access-Control) on your account
20     *
21     * **Scopes:** `role:read:admin`<br>
22     *  
23     *  **[Rate Limit Label](https://marketplace.zoom.us/docs/api-reference/rate-limits#rate-limits):** `Medium`<br>
24     * **Prerequisites** :
25     * *  Pro or higher plan.
26     * *  For setting the initial role, you must be the Account Owner.
27     * *  For subsequent role management, you must be the Account Owner or user with role management permissions.
28     */
29    pub async fn get(&self) -> ClientResult<crate::Response<crate::types::Domains>> {
30        let url = self.client.url("/roles", None);
31        self.client
32            .get(
33                &url,
34                crate::Message {
35                    body: None,
36                    content_type: None,
37                },
38            )
39            .await
40    }
41    /**
42     * Create a role.
43     *
44     * This function performs a `POST` to the `/roles` endpoint.
45     *
46     * Each Zoom user automatically has a role which can either be owner, administrator, or a member.
47     *
48     * **Pre-requisite:**<br>
49     * * Pro or higher plan.
50     * * For setting the initial role, you must be the Account Owner.<br>
51     * * For subsequent role management, you must be the Account Owner or user with role management permissions.<br>
52     * **Scopes:** `role:write:admin`<br>
53     *  
54     *  **[Rate Limit Label](https://marketplace.zoom.us/docs/api-reference/rate-limits#rate-limits):** `Light`
55     */
56    pub async fn create(
57        &self,
58        body: &crate::types::CreateRoleRequest,
59    ) -> ClientResult<crate::Response<()>> {
60        let url = self.client.url("/roles", None);
61        self.client
62            .post(
63                &url,
64                crate::Message {
65                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
66                    content_type: Some("application/json".to_string()),
67                },
68            )
69            .await
70    }
71    /**
72     * List members in a role.
73     *
74     * This function performs a `GET` to the `/roles/{roleId}/members` endpoint.
75     *
76     * User [roles](https://support.zoom.us/hc/en-us/articles/115001078646-Role-Based-Access-Control) can have a set of permissions that allows access only to the pages a user needs to view or edit. Use this API to list all the members that are assigned a specific role.
77     *
78     * **Scope:** `role:read:admin`<br>
79     *  
80     *  **[Rate Limit Label](https://marketplace.zoom.us/docs/api-reference/rate-limits#rate-limits):** `Medium`<br>**Prerequisites:**<br>
81     * * A Pro or a higher plan.
82     *
83     * **Parameters:**
84     *
85     * * `role_id: &str` -- User's first name.
86     * * `page_count: &str` -- The number of pages returned for this request.
87     * * `page_number: i64` --
88     *   **Deprecated** - This field has been deprecated and we will stop supporting it completely in a future release. Please use "next_page_token" for pagination instead of this field.
89     *   
90     *   The page number of the current page in the returned records.
91     * * `next_page_token: &str` -- The next page token is used to paginate through large result sets. A next page token will be returned whenever the set of available results exceeds the current page size. The expiration period for this token is 15 minutes.
92     * * `page_size: i64` -- The number of records returned within a single API call.
93     */
94    pub async fn members(
95        &self,
96        role_id: &str,
97        page_count: &str,
98        page_number: i64,
99        next_page_token: &str,
100        page_size: i64,
101    ) -> ClientResult<crate::Response<Vec<crate::types::Domains>>> {
102        let mut query_args: Vec<(String, String)> = Default::default();
103        if !next_page_token.is_empty() {
104            query_args.push(("next_page_token".to_string(), next_page_token.to_string()));
105        }
106        if !page_count.is_empty() {
107            query_args.push(("page_count".to_string(), page_count.to_string()));
108        }
109        if page_number > 0 {
110            query_args.push(("page_number".to_string(), page_number.to_string()));
111        }
112        if page_size > 0 {
113            query_args.push(("page_size".to_string(), page_size.to_string()));
114        }
115        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
116        let url = self.client.url(
117            &format!(
118                "/roles/{}/members?{}",
119                crate::progenitor_support::encode_path(role_id),
120                query_
121            ),
122            None,
123        );
124        let resp: crate::Response<crate::types::RoleMembersList> = self
125            .client
126            .get(
127                &url,
128                crate::Message {
129                    body: None,
130                    content_type: None,
131                },
132            )
133            .await?;
134
135        // Return our response data.
136        Ok(crate::Response::new(
137            resp.status,
138            resp.headers,
139            resp.body.members.to_vec(),
140        ))
141    }
142    /**
143     * List members in a role.
144     *
145     * This function performs a `GET` to the `/roles/{roleId}/members` endpoint.
146     *
147     * As opposed to `members`, this function returns all the pages of the request at once.
148     *
149     * User [roles](https://support.zoom.us/hc/en-us/articles/115001078646-Role-Based-Access-Control) can have a set of permissions that allows access only to the pages a user needs to view or edit. Use this API to list all the members that are assigned a specific role.
150     *
151     * **Scope:** `role:read:admin`<br>
152     *  
153     *  **[Rate Limit Label](https://marketplace.zoom.us/docs/api-reference/rate-limits#rate-limits):** `Medium`<br>**Prerequisites:**<br>
154     * * A Pro or a higher plan.
155     */
156    pub async fn get_all_members(
157        &self,
158        role_id: &str,
159        page_count: &str,
160    ) -> ClientResult<crate::Response<Vec<crate::types::Domains>>> {
161        let mut query_args: Vec<(String, String)> = Default::default();
162        if !page_count.is_empty() {
163            query_args.push(("page_count".to_string(), page_count.to_string()));
164        }
165        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
166        let url = self.client.url(
167            &format!(
168                "/roles/{}/members?{}",
169                crate::progenitor_support::encode_path(role_id),
170                query_
171            ),
172            None,
173        );
174        let crate::Response::<crate::types::RoleMembersList> {
175            mut status,
176            mut headers,
177            mut body,
178        } = self
179            .client
180            .get(
181                &url,
182                crate::Message {
183                    body: None,
184                    content_type: None,
185                },
186            )
187            .await?;
188
189        let mut members = body.members;
190        let mut page = body.next_page_token;
191
192        // Paginate if we should.
193        while !page.is_empty() {
194            // Check if we already have URL params and need to concat the token.
195            if !url.contains('?') {
196                crate::Response::<crate::types::RoleMembersList> {
197                    status,
198                    headers,
199                    body,
200                } = self
201                    .client
202                    .get(
203                        &format!("{}?next_page_token={}", url, page),
204                        crate::Message {
205                            body: None,
206                            content_type: None,
207                        },
208                    )
209                    .await?;
210            } else {
211                crate::Response::<crate::types::RoleMembersList> {
212                    status,
213                    headers,
214                    body,
215                } = self
216                    .client
217                    .get(
218                        &format!("{}&next_page_token={}", url, page),
219                        crate::Message {
220                            body: None,
221                            content_type: None,
222                        },
223                    )
224                    .await?;
225            }
226
227            members.append(&mut body.members);
228
229            if !body.next_page_token.is_empty() && body.next_page_token != page {
230                page = body.next_page_token.to_string();
231            } else {
232                page = "".to_string();
233            }
234        }
235
236        // Return our response data.
237        Ok(crate::Response::new(status, headers, members))
238    }
239    /**
240     * Assign a role.
241     *
242     * This function performs a `POST` to the `/roles/{roleId}/members` endpoint.
243     *
244     * User [roles](https://support.zoom.us/hc/en-us/articles/115001078646-Role-Based-Access-Control) can have a set of permissions that allows access only to the pages a user needs to view or edit. Use this API to [assign a role](https://support.zoom.us/hc/en-us/articles/115001078646-Role-Based-Access-Control#h_748b6fd8-5057-4cf4-bbfd-787909c09db0) to members.
245     *
246     * **Scopes:** `role:write:admin`<br>
247     *  
248     *  **[Rate Limit Label](https://marketplace.zoom.us/docs/api-reference/rate-limits#rate-limits):** `Medium`<br>
249     * **Prerequisites:**<br>
250     * * A Pro or a higher plan.
251     *
252     * **Parameters:**
253     *
254     * * `role_id: &str` -- User's first name.
255     */
256    pub async fn add_members(
257        &self,
258        role_id: &str,
259        body: &crate::types::AddRoleMembersRequest,
260    ) -> ClientResult<crate::Response<crate::types::AddRoleMembersResponse>> {
261        let url = self.client.url(
262            &format!(
263                "/roles/{}/members",
264                crate::progenitor_support::encode_path(role_id),
265            ),
266            None,
267        );
268        self.client
269            .post(
270                &url,
271                crate::Message {
272                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
273                    content_type: Some("application/json".to_string()),
274                },
275            )
276            .await
277    }
278    /**
279     * Unassign a role.
280     *
281     * This function performs a `DELETE` to the `/roles/{roleId}/members/{memberId}` endpoint.
282     *
283     * User [roles](https://support.zoom.us/hc/en-us/articles/115001078646-Role-Based-Access-Control) can have a set of permissions that allows access only to the pages a user needs to view or edit. Use this API to unassign a user's role.
284     *
285     * **Scope:** `role:write:admin`<br>
286     *  
287     *  **[Rate Limit Label](https://marketplace.zoom.us/docs/api-reference/rate-limits#rate-limits):** `Light`<br>
288     * **Prerequisites:**<br>
289     * * A Pro or a higher plan.
290     *
291     * **Parameters:**
292     *
293     * * `role_id: &str` -- User's first name.
294     * * `member_id: &str` -- User's first name.
295     */
296    pub async fn member_delete(
297        &self,
298        role_id: &str,
299        member_id: &str,
300    ) -> ClientResult<crate::Response<()>> {
301        let url = self.client.url(
302            &format!(
303                "/roles/{}/members/{}",
304                crate::progenitor_support::encode_path(role_id),
305                crate::progenitor_support::encode_path(member_id),
306            ),
307            None,
308        );
309        self.client
310            .delete(
311                &url,
312                crate::Message {
313                    body: None,
314                    content_type: None,
315                },
316            )
317            .await
318    }
319    /**
320     * Get role information.
321     *
322     * This function performs a `GET` to the `/roles/{roleId}` endpoint.
323     *
324     * Each Zoom user automatically has a role which can either be owner, administrator, or a member. Account Owners and users with edit privileges for Role management can add customized roles with a list of privileges.
325     *
326     * Use this API to get information including specific privileges assigned to a [role](https://support.zoom.us/hc/en-us/articles/115001078646-Role-Based-Access-Control).<br>
327     * **Pre-requisite:**<br>
328     * * A Pro or higher plan.<br>
329     * * For role management and updates, you must be the Account Owner or user with role management permissions.
330     *
331     * **Scopes:** `role:read:admin`<br>
332     *  
333     *  **[Rate Limit Label](https://marketplace.zoom.us/docs/api-reference/rate-limits#rate-limits):** `Light`
334     *
335     * **Parameters:**
336     *
337     * * `role_id: &str` -- User's first name.
338     */
339    pub async fn get_information(
340        &self,
341        role_id: &str,
342    ) -> ClientResult<crate::Response<crate::types::GetRoleInformationResponse>> {
343        let url = self.client.url(
344            &format!("/roles/{}", crate::progenitor_support::encode_path(role_id),),
345            None,
346        );
347        self.client
348            .get(
349                &url,
350                crate::Message {
351                    body: None,
352                    content_type: None,
353                },
354            )
355            .await
356    }
357    /**
358     * Delete a role.
359     *
360     * This function performs a `DELETE` to the `/roles/{roleId}` endpoint.
361     *
362     * Each Zoom user automatically has a role which can either be owner, administrator, or a member. Account Owners and users with edit privileges for Role management can add customized roles with a list.
363     *
364     * Use this API to delete a role.<br>
365     * **Pre-requisite:**<br>
366     * * A Pro or higher plan.<br>
367     * * For role management and updates, you must be the Account Owner or user with role management permissions.
368     *
369     * **Scopes:** `role:write:admin`<br>
370     *  
371     *  **[Rate Limit Label](https://marketplace.zoom.us/docs/api-reference/rate-limits#rate-limits):** `Light`
372     *
373     * **Parameters:**
374     *
375     * * `role_id: &str` -- User's first name.
376     */
377    pub async fn delete(&self, role_id: &str) -> ClientResult<crate::Response<()>> {
378        let url = self.client.url(
379            &format!("/roles/{}", crate::progenitor_support::encode_path(role_id),),
380            None,
381        );
382        self.client
383            .delete(
384                &url,
385                crate::Message {
386                    body: None,
387                    content_type: None,
388                },
389            )
390            .await
391    }
392    /**
393     * Update role information.
394     *
395     * This function performs a `PATCH` to the `/roles/{roleId}` endpoint.
396     *
397     * Each Zoom user automatically has a [role](https://support.zoom.us/hc/en-us/articles/115001078646-Role-Based-Access-Control) which can either be owner, administrator, or a member. Account Owners and users with edit privileges for Role management can add customized roles with a list.
398     *
399     * Use this API to change the privileges, name and description of a specific role.<br>
400     * **Pre-requisite:**<br>
401     * * A Pro or higher plan.<br>
402     * * For role management and updates, you must be the Account Owner or user with role management permissions.<br>**Scopes:** `role:write:admin`<br>
403     *  
404     *  **[Rate Limit Label](https://marketplace.zoom.us/docs/api-reference/rate-limits#rate-limits):** `Light`
405     *
406     * **Parameters:**
407     *
408     * * `role_id: &str` -- User's first name.
409     */
410    pub async fn update(
411        &self,
412        role_id: &str,
413        body: &crate::types::UpdateRoleRequest,
414    ) -> ClientResult<crate::Response<()>> {
415        let url = self.client.url(
416            &format!("/roles/{}", crate::progenitor_support::encode_path(role_id),),
417            None,
418        );
419        self.client
420            .patch(
421                &url,
422                crate::Message {
423                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
424                    content_type: Some("application/json".to_string()),
425                },
426            )
427            .await
428    }
429}