sendgrid_api/teammates.rs
1use crate::Client;
2use crate::ClientResult;
3
4pub struct Teammates {
5 pub client: Client,
6}
7
8impl Teammates {
9 #[doc(hidden)]
10 pub fn new(client: Client) -> Self {
11 Teammates { client }
12 }
13
14 /**
15 * Retrieve all teammates.
16 *
17 * This function performs a `GET` to the `/teammates` endpoint.
18 *
19 * **This endpoint allows you to retrieve a list of all current Teammates.**
20 *
21 * You can limit the number of results returned using the `limit` query paramater. To return results from a specific Teammate, use the `offset` paramter. The Response Headers will include pagination info.
22 *
23 * **Parameters:**
24 *
25 * * `limit: u64` -- Number of items to return.
26 * * `offset: u64` -- Paging offset.
27 * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
28 */
29 pub async fn get(
30 &self,
31 limit: u64,
32 offset: u64,
33 ) -> ClientResult<crate::Response<crate::types::GetTeammatesResponse>> {
34 let mut query_args: Vec<(String, String)> = Default::default();
35 if !limit.to_string().is_empty() {
36 query_args.push(("limit".to_string(), limit.to_string()));
37 }
38 if !offset.to_string().is_empty() {
39 query_args.push(("offset".to_string(), offset.to_string()));
40 }
41 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
42 let url = self.client.url(&format!("/teammates?{}", query_), None);
43 self.client
44 .get(
45 &url,
46 crate::Message {
47 body: None,
48 content_type: None,
49 },
50 )
51 .await
52 }
53 /**
54 * Invite teammate.
55 *
56 * This function performs a `POST` to the `/teammates` endpoint.
57 *
58 * **This endpoint allows you to invite a Teammate to your account via email.**
59 *
60 * You can set a Teammate's initial permissions using the `scopes` array in the request body. Teammate's will receive a minimum set of scopes from Twilio SendGrid that are necessary for the Teammate to function.
61 *
62 * **Note:** A teammate invite will expire after 7 days, but you may resend the invitation at any time to reset the expiration date.
63 *
64 * **Parameters:**
65 *
66 * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
67 */
68 pub async fn post(
69 &self,
70 body: &crate::types::PostTeammatesRequest,
71 ) -> ClientResult<crate::Response<crate::types::PostTeammatesResponse>> {
72 let url = self.client.url("/teammates", None);
73 self.client
74 .post(
75 &url,
76 crate::Message {
77 body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
78 content_type: Some("application/json".to_string()),
79 },
80 )
81 .await
82 }
83 /**
84 * Resend teammate invite.
85 *
86 * This function performs a `POST` to the `/teammates/pending/{token}/resend` endpoint.
87 *
88 * **This endpoint allows you to resend a Teammate invitation.**
89 *
90 * Teammate invitations will expire after 7 days. Resending an invitation will reset the expiration date.
91 *
92 * **Parameters:**
93 *
94 * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
95 */
96 pub async fn post_pending_token_resend(
97 &self,
98 token: &str,
99 ) -> ClientResult<crate::Response<crate::types::PostTeammatesResponse>> {
100 let url = self.client.url(
101 &format!(
102 "/teammates/pending/{}/resend",
103 crate::progenitor_support::encode_path(token),
104 ),
105 None,
106 );
107 self.client
108 .post(
109 &url,
110 crate::Message {
111 body: None,
112 content_type: None,
113 },
114 )
115 .await
116 }
117 /**
118 * Retrieve access requests.
119 *
120 * This function performs a `GET` to the `/scopes/requests` endpoint.
121 *
122 * **This endpoint allows you to retrieve a list of all recent access requests.**
123 *
124 * The Response Header's `link` parameter will include pagination info.
125 *
126 * **Parameters:**
127 *
128 * * `limit: i64` -- Optional field to limit the number of results returned.
129 * * `offset: i64` -- Optional beginning point in the list to retrieve from.
130 */
131 pub async fn get_scopes_requests(
132 &self,
133 limit: i64,
134 offset: i64,
135 ) -> ClientResult<crate::Response<Vec<crate::types::GetScopesRequestsResponse>>> {
136 let mut query_args: Vec<(String, String)> = Default::default();
137 if limit > 0 {
138 query_args.push(("limit".to_string(), limit.to_string()));
139 }
140 if offset > 0 {
141 query_args.push(("offset".to_string(), offset.to_string()));
142 }
143 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
144 let url = self
145 .client
146 .url(&format!("/scopes/requests?{}", query_), None);
147 self.client
148 .get(
149 &url,
150 crate::Message {
151 body: None,
152 content_type: None,
153 },
154 )
155 .await
156 }
157 /**
158 * Retrieve access requests.
159 *
160 * This function performs a `GET` to the `/scopes/requests` endpoint.
161 *
162 * As opposed to `get_scopes_requests`, this function returns all the pages of the request at once.
163 *
164 * **This endpoint allows you to retrieve a list of all recent access requests.**
165 *
166 * The Response Header's `link` parameter will include pagination info.
167 */
168 pub async fn get_all_scopes_requests(
169 &self,
170 offset: i64,
171 ) -> ClientResult<crate::Response<Vec<crate::types::GetScopesRequestsResponse>>> {
172 let mut query_args: Vec<(String, String)> = Default::default();
173 if offset > 0 {
174 query_args.push(("offset".to_string(), offset.to_string()));
175 }
176 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
177 let url = self
178 .client
179 .url(&format!("/scopes/requests?{}", query_), None);
180 self.client
181 .get_all_pages(
182 &url,
183 crate::Message {
184 body: None,
185 content_type: None,
186 },
187 )
188 .await
189 }
190 /**
191 * Retrieve all pending teammates.
192 *
193 * This function performs a `GET` to the `/teammates/pending` endpoint.
194 *
195 * **This endpoint allows you to retrieve a list of all pending Teammate invitations.**
196 *
197 * Each teammate invitation is valid for 7 days. Users may resend the invitation to refresh the expiration date.
198 *
199 * **Parameters:**
200 *
201 * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
202 */
203 pub async fn get_pending(
204 &self,
205 ) -> ClientResult<crate::Response<crate::types::GetTeammatesPendingResponse>> {
206 let url = self.client.url("/teammates/pending", None);
207 self.client
208 .get(
209 &url,
210 crate::Message {
211 body: None,
212 content_type: None,
213 },
214 )
215 .await
216 }
217 /**
218 * Retrieve specific teammate.
219 *
220 * This function performs a `GET` to the `/teammates/{username}` endpoint.
221 *
222 * **This endpoint allows you to retrieve a specific Teammate by username.**
223 *
224 * You can retrieve the username's for each of your Teammates using the "Retrieve all Teammates" endpoint.
225 *
226 * **Parameters:**
227 *
228 * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
229 */
230 pub async fn get_username(
231 &self,
232 username: &str,
233 ) -> ClientResult<crate::Response<crate::types::GetTeammatesUsernameResponse>> {
234 let url = self.client.url(
235 &format!(
236 "/teammates/{}",
237 crate::progenitor_support::encode_path(username),
238 ),
239 None,
240 );
241 self.client
242 .get(
243 &url,
244 crate::Message {
245 body: None,
246 content_type: None,
247 },
248 )
249 .await
250 }
251 /**
252 * Delete teammate.
253 *
254 * This function performs a `DELETE` to the `/teammates/{username}` endpoint.
255 *
256 * **This endpoint allows you to delete a teammate.**
257 *
258 * **Only the parent user or an admin teammate can delete another teammate.**
259 *
260 * **Parameters:**
261 *
262 * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
263 */
264 pub async fn delete_username(
265 &self,
266 username: &str,
267 ) -> ClientResult<crate::Response<crate::types::PostSendersResponse>> {
268 let url = self.client.url(
269 &format!(
270 "/teammates/{}",
271 crate::progenitor_support::encode_path(username),
272 ),
273 None,
274 );
275 self.client
276 .delete(
277 &url,
278 crate::Message {
279 body: None,
280 content_type: None,
281 },
282 )
283 .await
284 }
285 /**
286 * Update teammate's permissions.
287 *
288 * This function performs a `PATCH` to the `/teammates/{username}` endpoint.
289 *
290 * **This endpoint allows you to update a teammate’s permissions.**
291 *
292 * To turn a teammate into an admin, the request body should contain an `is_admin` set to `true`. Otherwise, set `is_admin` to `false` and pass in all the scopes that a teammate should have.
293 *
294 * **Only the parent user or other admin teammates can update another teammate’s permissions.**
295 *
296 * **Admin users can only update permissions.**
297 *
298 * **Parameters:**
299 *
300 * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
301 */
302 pub async fn patch_username(
303 &self,
304 username: &str,
305 body: &crate::types::PatchTeammatesUsernameRequest,
306 ) -> ClientResult<crate::Response<crate::types::GetTeammatesUsernameResponse>> {
307 let url = self.client.url(
308 &format!(
309 "/teammates/{}",
310 crate::progenitor_support::encode_path(username),
311 ),
312 None,
313 );
314 self.client
315 .patch(
316 &url,
317 crate::Message {
318 body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
319 content_type: Some("application/json".to_string()),
320 },
321 )
322 .await
323 }
324 /**
325 * Approve access request.
326 *
327 * This function performs a `PATCH` to the `/scopes/requests/{request_id}/approve` endpoint.
328 *
329 * **This endpoint allows you to approve an access attempt.**
330 *
331 * **Note:** Only teammate admins may approve another teammate’s access request.
332 */
333 pub async fn patch_scopes_requests_approve(
334 &self,
335 request_id: &str,
336 ) -> ClientResult<crate::Response<crate::types::PatchScopesRequestsApproveResponse>> {
337 let url = self.client.url(
338 &format!(
339 "/scopes/requests/{}/approve",
340 crate::progenitor_support::encode_path(request_id),
341 ),
342 None,
343 );
344 self.client
345 .patch(
346 &url,
347 crate::Message {
348 body: None,
349 content_type: None,
350 },
351 )
352 .await
353 }
354 /**
355 * Deny access request.
356 *
357 * This function performs a `DELETE` to the `/scopes/requests/{request_id}` endpoint.
358 *
359 * **This endpoint allows you to deny an attempt to access your account.**
360 *
361 * **Note:** Only teammate admins may delete a teammate's access request.
362 */
363 pub async fn delete_scopes_requests_request(
364 &self,
365 request_id: &str,
366 ) -> ClientResult<crate::Response<()>> {
367 let url = self.client.url(
368 &format!(
369 "/scopes/requests/{}",
370 crate::progenitor_support::encode_path(request_id),
371 ),
372 None,
373 );
374 self.client
375 .delete(
376 &url,
377 crate::Message {
378 body: None,
379 content_type: None,
380 },
381 )
382 .await
383 }
384 /**
385 * Delete pending teammate.
386 *
387 * This function performs a `DELETE` to the `/teammates/pending/{token}` endpoint.
388 *
389 * **This endpoint allows you to delete a pending teammate invite.**
390 *
391 * **Parameters:**
392 *
393 * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
394 */
395 pub async fn delete_pending_token(&self, token: &str) -> ClientResult<crate::Response<()>> {
396 let url = self.client.url(
397 &format!(
398 "/teammates/pending/{}",
399 crate::progenitor_support::encode_path(token),
400 ),
401 None,
402 );
403 self.client
404 .delete(
405 &url,
406 crate::Message {
407 body: None,
408 content_type: None,
409 },
410 )
411 .await
412 }
413}