gsuite_api/members.rs
1use crate::Client;
2use crate::ClientResult;
3
4pub struct Members {
5 pub client: Client,
6}
7
8impl Members {
9 #[doc(hidden)]
10 pub fn new(client: Client) -> Self {
11 Members { client }
12 }
13
14 /**
15 * This function performs a `GET` to the `/admin/directory/v1/groups/{groupKey}/hasMember/{memberKey}` endpoint.
16 *
17 * Checks whether the given user is a member of the group. Membership can be direct or nested.
18 *
19 * **Parameters:**
20 *
21 * * `group_key: &str` -- Identifies the group in the API request. The value can be the group's email address, group alias, or the unique group ID.
22 * * `member_key: &str` -- Identifies the user member in the API request. The value can be the user's primary email address, alias, or unique ID.
23 */
24 pub async fn has(
25 &self,
26 group_key: &str,
27 member_key: &str,
28 ) -> ClientResult<crate::Response<crate::types::MembersHasMember>> {
29 let url = self.client.url(
30 &format!(
31 "/admin/directory/v1/groups/{}/hasMember/{}",
32 crate::progenitor_support::encode_path(group_key),
33 crate::progenitor_support::encode_path(member_key),
34 ),
35 None,
36 );
37 self.client
38 .get(
39 &url,
40 crate::Message {
41 body: None,
42 content_type: None,
43 },
44 )
45 .await
46 }
47 /**
48 * This function performs a `GET` to the `/admin/directory/v1/groups/{groupKey}/members` endpoint.
49 *
50 * Retrieves a paginated list of all members in a group.
51 *
52 * **Parameters:**
53 *
54 * * `group_key: &str` -- Identifies the group in the API request. The value can be the group's email address, group alias, or the unique group ID.
55 * * `include_derived_membership: bool` -- A Boolean value to indicate whether payload is wanted. Optional.
56 * * `max_results: i64` -- Maximum number of results to return. Max allowed value is 200.
57 * * `page_token: &str` -- Token to specify next page in the list.
58 * * `roles: &str` -- The `roles` query parameter allows you to retrieve group members by role. Allowed values are `OWNER`, `MANAGER`, and `MEMBER`.
59 */
60 pub async fn list(
61 &self,
62 group_key: &str,
63 include_derived_membership: bool,
64 max_results: i64,
65 page_token: &str,
66 roles: &str,
67 ) -> ClientResult<crate::Response<Vec<crate::types::Member>>> {
68 let mut query_args: Vec<(String, String)> = Default::default();
69 if include_derived_membership {
70 query_args.push((
71 "includeDerivedMembership".to_string(),
72 include_derived_membership.to_string(),
73 ));
74 }
75 if max_results > 0 {
76 query_args.push(("maxResults".to_string(), max_results.to_string()));
77 }
78 if !page_token.is_empty() {
79 query_args.push(("pageToken".to_string(), page_token.to_string()));
80 }
81 if !roles.is_empty() {
82 query_args.push(("roles".to_string(), roles.to_string()));
83 }
84 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
85 let url = self.client.url(
86 &format!(
87 "/admin/directory/v1/groups/{}/members?{}",
88 crate::progenitor_support::encode_path(group_key),
89 query_
90 ),
91 None,
92 );
93 let resp: crate::Response<crate::types::Members> = self
94 .client
95 .get(
96 &url,
97 crate::Message {
98 body: None,
99 content_type: None,
100 },
101 )
102 .await?;
103
104 // Return our response data.
105 Ok(crate::Response::new(
106 resp.status,
107 resp.headers,
108 resp.body.members.to_vec(),
109 ))
110 }
111 /**
112 * This function performs a `GET` to the `/admin/directory/v1/groups/{groupKey}/members` endpoint.
113 *
114 * As opposed to `list`, this function returns all the pages of the request at once.
115 *
116 * Retrieves a paginated list of all members in a group.
117 */
118 pub async fn list_all(
119 &self,
120 group_key: &str,
121 include_derived_membership: bool,
122 roles: &str,
123 ) -> ClientResult<crate::Response<Vec<crate::types::Member>>> {
124 let mut query_args: Vec<(String, String)> = Default::default();
125 if include_derived_membership {
126 query_args.push((
127 "includeDerivedMembership".to_string(),
128 include_derived_membership.to_string(),
129 ));
130 }
131 if !roles.is_empty() {
132 query_args.push(("roles".to_string(), roles.to_string()));
133 }
134 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
135 let url = self.client.url(
136 &format!(
137 "/admin/directory/v1/groups/{}/members?{}",
138 crate::progenitor_support::encode_path(group_key),
139 query_
140 ),
141 None,
142 );
143 let crate::Response::<crate::types::Members> {
144 mut status,
145 mut headers,
146 mut body,
147 } = self
148 .client
149 .get(
150 &url,
151 crate::Message {
152 body: None,
153 content_type: None,
154 },
155 )
156 .await?;
157
158 let mut members = body.members;
159 let mut page = body.next_page_token;
160
161 // Paginate if we should.
162 while !page.is_empty() {
163 if !url.contains('?') {
164 crate::Response::<crate::types::Members> {
165 status,
166 headers,
167 body,
168 } = self
169 .client
170 .get(
171 &format!("{}?pageToken={}", url, page),
172 crate::Message {
173 body: None,
174 content_type: None,
175 },
176 )
177 .await?;
178 } else {
179 crate::Response::<crate::types::Members> {
180 status,
181 headers,
182 body,
183 } = self
184 .client
185 .get(
186 &format!("{}&pageToken={}", url, page),
187 crate::Message {
188 body: None,
189 content_type: None,
190 },
191 )
192 .await?;
193 }
194
195 members.append(&mut body.members);
196
197 if !body.next_page_token.is_empty() && body.next_page_token != page {
198 page = body.next_page_token.to_string();
199 } else {
200 page = "".to_string();
201 }
202 }
203
204 // Return our response data.
205 Ok(crate::Response::new(status, headers, members))
206 }
207 /**
208 * This function performs a `POST` to the `/admin/directory/v1/groups/{groupKey}/members` endpoint.
209 *
210 * Adds a user to the specified group.
211 *
212 * **Parameters:**
213 *
214 * * `group_key: &str` -- Identifies the group in the API request. The value can be the group's email address, group alias, or the unique group ID.
215 */
216 pub async fn insert(
217 &self,
218 group_key: &str,
219 body: &crate::types::Member,
220 ) -> ClientResult<crate::Response<crate::types::Member>> {
221 let url = self.client.url(
222 &format!(
223 "/admin/directory/v1/groups/{}/members",
224 crate::progenitor_support::encode_path(group_key),
225 ),
226 None,
227 );
228 self.client
229 .post(
230 &url,
231 crate::Message {
232 body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
233 content_type: Some("application/json".to_string()),
234 },
235 )
236 .await
237 }
238 /**
239 * This function performs a `GET` to the `/admin/directory/v1/groups/{groupKey}/members/{memberKey}` endpoint.
240 *
241 * Retrieves a group member's properties.
242 *
243 * **Parameters:**
244 *
245 * * `group_key: &str` -- Identifies the group in the API request. The value can be the group's email address, group alias, or the unique group ID.
246 * * `member_key: &str` -- Identifies the group member in the API request. A group member can be a user or another group. The value can be the member's (group or user) primary email address, alias, or unique ID.
247 */
248 pub async fn get(
249 &self,
250 group_key: &str,
251 member_key: &str,
252 ) -> ClientResult<crate::Response<crate::types::Member>> {
253 let url = self.client.url(
254 &format!(
255 "/admin/directory/v1/groups/{}/members/{}",
256 crate::progenitor_support::encode_path(group_key),
257 crate::progenitor_support::encode_path(member_key),
258 ),
259 None,
260 );
261 self.client
262 .get(
263 &url,
264 crate::Message {
265 body: None,
266 content_type: None,
267 },
268 )
269 .await
270 }
271 /**
272 * This function performs a `PUT` to the `/admin/directory/v1/groups/{groupKey}/members/{memberKey}` endpoint.
273 *
274 * Updates the membership of a user in the specified group.
275 *
276 * **Parameters:**
277 *
278 * * `group_key: &str` -- Identifies the group in the API request. The value can be the group's email address, group alias, or the unique group ID.
279 * * `member_key: &str` -- Identifies the group member in the API request. A group member can be a user or another group. The value can be the member's (group or user) primary email address, alias, or unique ID.
280 */
281 pub async fn update(
282 &self,
283 group_key: &str,
284 member_key: &str,
285 body: &crate::types::Member,
286 ) -> ClientResult<crate::Response<crate::types::Member>> {
287 let url = self.client.url(
288 &format!(
289 "/admin/directory/v1/groups/{}/members/{}",
290 crate::progenitor_support::encode_path(group_key),
291 crate::progenitor_support::encode_path(member_key),
292 ),
293 None,
294 );
295 self.client
296 .put(
297 &url,
298 crate::Message {
299 body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
300 content_type: Some("application/json".to_string()),
301 },
302 )
303 .await
304 }
305 /**
306 * This function performs a `DELETE` to the `/admin/directory/v1/groups/{groupKey}/members/{memberKey}` endpoint.
307 *
308 * Removes a member from a group.
309 *
310 * **Parameters:**
311 *
312 * * `group_key: &str` -- Identifies the group in the API request. The value can be the group's email address, group alias, or the unique group ID.
313 * * `member_key: &str` -- Identifies the group member in the API request. A group member can be a user or another group. The value can be the member's (group or user) primary email address, alias, or unique ID.
314 */
315 pub async fn delete(
316 &self,
317 group_key: &str,
318 member_key: &str,
319 ) -> ClientResult<crate::Response<()>> {
320 let url = self.client.url(
321 &format!(
322 "/admin/directory/v1/groups/{}/members/{}",
323 crate::progenitor_support::encode_path(group_key),
324 crate::progenitor_support::encode_path(member_key),
325 ),
326 None,
327 );
328 self.client
329 .delete(
330 &url,
331 crate::Message {
332 body: None,
333 content_type: None,
334 },
335 )
336 .await
337 }
338 /**
339 * This function performs a `PATCH` to the `/admin/directory/v1/groups/{groupKey}/members/{memberKey}` endpoint.
340 *
341 * Updates the membership properties of a user in the specified group. This method supports [patch semantics](/admin-sdk/directory/v1/guides/performance#patch).
342 *
343 * **Parameters:**
344 *
345 * * `group_key: &str` -- Identifies the group in the API request. The value can be the group's email address, group alias, or the unique group ID.
346 * * `member_key: &str` -- Identifies the group member in the API request. A group member can be a user or another group. The value can be the member's (group or user) primary email address, alias, or unique ID.
347 */
348 pub async fn patch(
349 &self,
350 group_key: &str,
351 member_key: &str,
352 body: &crate::types::Member,
353 ) -> ClientResult<crate::Response<crate::types::Member>> {
354 let url = self.client.url(
355 &format!(
356 "/admin/directory/v1/groups/{}/members/{}",
357 crate::progenitor_support::encode_path(group_key),
358 crate::progenitor_support::encode_path(member_key),
359 ),
360 None,
361 );
362 self.client
363 .patch(
364 &url,
365 crate::Message {
366 body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
367 content_type: Some("application/json".to_string()),
368 },
369 )
370 .await
371 }
372}