gsuite_api/
customers.rs

1use crate::Client;
2use crate::ClientResult;
3
4pub struct Customers {
5    pub client: Client,
6}
7
8impl Customers {
9    #[doc(hidden)]
10    pub fn new(client: Client) -> Self {
11        Customers { client }
12    }
13
14    /**
15     * This function performs a `GET` to the `/admin/directory/v1/customers/{customerKey}` endpoint.
16     *
17     * Retrieves a customer.
18     *
19     * **Parameters:**
20     *
21     * * `customer_key: &str` -- Id of the customer to be retrieved.
22     */
23    pub async fn get(
24        &self,
25        customer_key: &str,
26    ) -> ClientResult<crate::Response<crate::types::Customer>> {
27        let url = self.client.url(
28            &format!(
29                "/admin/directory/v1/customers/{}",
30                crate::progenitor_support::encode_path(customer_key),
31            ),
32            None,
33        );
34        self.client
35            .get(
36                &url,
37                crate::Message {
38                    body: None,
39                    content_type: None,
40                },
41            )
42            .await
43    }
44    /**
45     * This function performs a `PUT` to the `/admin/directory/v1/customers/{customerKey}` endpoint.
46     *
47     * Updates a customer.
48     *
49     * **Parameters:**
50     *
51     * * `customer_key: &str` -- Id of the customer to be updated.
52     */
53    pub async fn update(
54        &self,
55        customer_key: &str,
56        body: &crate::types::Customer,
57    ) -> ClientResult<crate::Response<crate::types::Customer>> {
58        let url = self.client.url(
59            &format!(
60                "/admin/directory/v1/customers/{}",
61                crate::progenitor_support::encode_path(customer_key),
62            ),
63            None,
64        );
65        self.client
66            .put(
67                &url,
68                crate::Message {
69                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
70                    content_type: Some("application/json".to_string()),
71                },
72            )
73            .await
74    }
75    /**
76     * This function performs a `PATCH` to the `/admin/directory/v1/customers/{customerKey}` endpoint.
77     *
78     * Patches a customer.
79     *
80     * **Parameters:**
81     *
82     * * `customer_key: &str` -- Id of the customer to be updated.
83     */
84    pub async fn patch(
85        &self,
86        customer_key: &str,
87        body: &crate::types::Customer,
88    ) -> ClientResult<crate::Response<crate::types::Customer>> {
89        let url = self.client.url(
90            &format!(
91                "/admin/directory/v1/customers/{}",
92                crate::progenitor_support::encode_path(customer_key),
93            ),
94            None,
95        );
96        self.client
97            .patch(
98                &url,
99                crate::Message {
100                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
101                    content_type: Some("application/json".to_string()),
102                },
103            )
104            .await
105    }
106    /**
107     * This function performs a `GET` to the `/admin/directory/v1/{name}` endpoint.
108     *
109     * Returns a `Printer` resource (printer's config).
110     *
111     * **Parameters:**
112     *
113     * * `name: &str` -- Required. The name of the printer to retrieve. Format: customers/{customer_id}/chrome/printers/{printer_id}.
114     */
115    pub async fn admin_chrome_printers_get(
116        &self,
117        name: &str,
118    ) -> ClientResult<crate::Response<crate::types::Printer>> {
119        let url = self.client.url(
120            &format!(
121                "/admin/directory/v1/{}",
122                crate::progenitor_support::encode_path(name),
123            ),
124            None,
125        );
126        self.client
127            .get(
128                &url,
129                crate::Message {
130                    body: None,
131                    content_type: None,
132                },
133            )
134            .await
135    }
136    /**
137     * This function performs a `DELETE` to the `/admin/directory/v1/{name}` endpoint.
138     *
139     * Deletes a `Printer`.
140     *
141     * **Parameters:**
142     *
143     * * `name: &str` -- Required. The name of the printer to be updated. Format: customers/{customer_id}/chrome/printers/{printer_id}.
144     */
145    pub async fn admin_chrome_printers_delete(
146        &self,
147        name: &str,
148    ) -> ClientResult<crate::Response<crate::types::Empty>> {
149        let url = self.client.url(
150            &format!(
151                "/admin/directory/v1/{}",
152                crate::progenitor_support::encode_path(name),
153            ),
154            None,
155        );
156        self.client
157            .delete(
158                &url,
159                crate::Message {
160                    body: None,
161                    content_type: None,
162                },
163            )
164            .await
165    }
166    /**
167     * This function performs a `PATCH` to the `/admin/directory/v1/{name}` endpoint.
168     *
169     * Updates a `Printer` resource.
170     *
171     * **Parameters:**
172     *
173     * * `name: &str` -- The resource name of the Printer object, in the format customers/{customer-id}/printers/{printer-id} (During printer creation leave empty).
174     * * `clear_mask: &str` -- The list of fields to be cleared. Note, some of the fields are read only and cannot be updated. Values for not specified fields will be patched.
175     * * `update_mask: &str` -- The list of fields to be updated. Note, some of the fields are read only and cannot be updated. Values for not specified fields will be patched.
176     */
177    pub async fn admin_chrome_printers_patch(
178        &self,
179        name: &str,
180        clear_mask: &str,
181        update_mask: &str,
182        body: &crate::types::Printer,
183    ) -> ClientResult<crate::Response<crate::types::Printer>> {
184        let mut query_args: Vec<(String, String)> = Default::default();
185        if !clear_mask.is_empty() {
186            query_args.push(("clearMask".to_string(), clear_mask.to_string()));
187        }
188        if !update_mask.is_empty() {
189            query_args.push(("updateMask".to_string(), update_mask.to_string()));
190        }
191        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
192        let url = self.client.url(
193            &format!(
194                "/admin/directory/v1/{}?{}",
195                crate::progenitor_support::encode_path(name),
196                query_
197            ),
198            None,
199        );
200        self.client
201            .patch(
202                &url,
203                crate::Message {
204                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
205                    content_type: Some("application/json".to_string()),
206                },
207            )
208            .await
209    }
210    /**
211     * This function performs a `GET` to the `/admin/directory/v1/{parent}/chrome/printers` endpoint.
212     *
213     * List printers configs.
214     *
215     * **Parameters:**
216     *
217     * * `parent: &str` -- Required. The name of the customer who owns this collection of printers. Format: customers/{customer_id}.
218     * * `filter: &str` -- Search query. Search syntax is shared between this api and Admin Console printers pages.
219     * * `org_unit_id: &str` -- Organization Unit that we want to list the printers for. When org_unit is not present in the request then all printers of the customer are returned (or filtered). When org_unit is present in the request then only printers available to this OU will be returned (owned or inherited). You may see if printer is owned or inherited for this OU by looking at Printer.org_unit_id.
220     * * `page_size: i64` -- The maximum number of objects to return. The service may return fewer than this value.
221     * * `page_token: &str` -- A page token, received from a previous call.
222     */
223    pub async fn admin_chrome_printers_list(
224        &self,
225        parent: &str,
226        filter: &str,
227        org_unit_id: &str,
228        page_size: i64,
229        page_token: &str,
230    ) -> ClientResult<crate::Response<Vec<crate::types::Printer>>> {
231        let mut query_args: Vec<(String, String)> = Default::default();
232        if !filter.is_empty() {
233            query_args.push(("filter".to_string(), filter.to_string()));
234        }
235        if !org_unit_id.is_empty() {
236            query_args.push(("orgUnitId".to_string(), org_unit_id.to_string()));
237        }
238        if page_size > 0 {
239            query_args.push(("pageSize".to_string(), page_size.to_string()));
240        }
241        if !page_token.is_empty() {
242            query_args.push(("pageToken".to_string(), page_token.to_string()));
243        }
244        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
245        let url = self.client.url(
246            &format!(
247                "/admin/directory/v1/{}/chrome/printers?{}",
248                crate::progenitor_support::encode_path(parent),
249                query_
250            ),
251            None,
252        );
253        let resp: crate::Response<crate::types::ListPrintersResponse> = self
254            .client
255            .get(
256                &url,
257                crate::Message {
258                    body: None,
259                    content_type: None,
260                },
261            )
262            .await?;
263
264        // Return our response data.
265        Ok(crate::Response::new(
266            resp.status,
267            resp.headers,
268            resp.body.printers.to_vec(),
269        ))
270    }
271    /**
272     * This function performs a `GET` to the `/admin/directory/v1/{parent}/chrome/printers` endpoint.
273     *
274     * As opposed to `admin_chrome_printers_list`, this function returns all the pages of the request at once.
275     *
276     * List printers configs.
277     */
278    pub async fn admin_chrome_printers_list_all(
279        &self,
280        parent: &str,
281        filter: &str,
282        org_unit_id: &str,
283    ) -> ClientResult<crate::Response<Vec<crate::types::Printer>>> {
284        let mut query_args: Vec<(String, String)> = Default::default();
285        if !filter.is_empty() {
286            query_args.push(("filter".to_string(), filter.to_string()));
287        }
288        if !org_unit_id.is_empty() {
289            query_args.push(("orgUnitId".to_string(), org_unit_id.to_string()));
290        }
291        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
292        let url = self.client.url(
293            &format!(
294                "/admin/directory/v1/{}/chrome/printers?{}",
295                crate::progenitor_support::encode_path(parent),
296                query_
297            ),
298            None,
299        );
300        let crate::Response::<crate::types::ListPrintersResponse> {
301            mut status,
302            mut headers,
303            mut body,
304        } = self
305            .client
306            .get(
307                &url,
308                crate::Message {
309                    body: None,
310                    content_type: None,
311                },
312            )
313            .await?;
314
315        let mut printers = body.printers;
316        let mut page = body.next_page_token;
317
318        // Paginate if we should.
319        while !page.is_empty() {
320            if !url.contains('?') {
321                crate::Response::<crate::types::ListPrintersResponse> {
322                    status,
323                    headers,
324                    body,
325                } = self
326                    .client
327                    .get(
328                        &format!("{}?pageToken={}", url, page),
329                        crate::Message {
330                            body: None,
331                            content_type: None,
332                        },
333                    )
334                    .await?;
335            } else {
336                crate::Response::<crate::types::ListPrintersResponse> {
337                    status,
338                    headers,
339                    body,
340                } = self
341                    .client
342                    .get(
343                        &format!("{}&pageToken={}", url, page),
344                        crate::Message {
345                            body: None,
346                            content_type: None,
347                        },
348                    )
349                    .await?;
350            }
351
352            printers.append(&mut body.printers);
353
354            if !body.next_page_token.is_empty() && body.next_page_token != page {
355                page = body.next_page_token.to_string();
356            } else {
357                page = "".to_string();
358            }
359        }
360
361        // Return our response data.
362        Ok(crate::Response::new(status, headers, printers))
363    }
364    /**
365     * This function performs a `POST` to the `/admin/directory/v1/{parent}/chrome/printers` endpoint.
366     *
367     * Creates a printer under given Organization Unit.
368     *
369     * **Parameters:**
370     *
371     * * `parent: &str` -- Required. The name of the customer. Format: customers/{customer_id}.
372     */
373    pub async fn admin_chrome_printers_create(
374        &self,
375        parent: &str,
376        body: &crate::types::Printer,
377    ) -> ClientResult<crate::Response<crate::types::Printer>> {
378        let url = self.client.url(
379            &format!(
380                "/admin/directory/v1/{}/chrome/printers",
381                crate::progenitor_support::encode_path(parent),
382            ),
383            None,
384        );
385        self.client
386            .post(
387                &url,
388                crate::Message {
389                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
390                    content_type: Some("application/json".to_string()),
391                },
392            )
393            .await
394    }
395    /**
396     * This function performs a `POST` to the `/admin/directory/v1/{parent}/chrome/printers:batchCreatePrinters` endpoint.
397     *
398     * Creates printers under given Organization Unit.
399     *
400     * **Parameters:**
401     *
402     * * `parent: &str` -- Required. The name of the customer. Format: customers/{customer_id}.
403     */
404    pub async fn admin_chrome_printers_batch_create(
405        &self,
406        parent: &str,
407        body: &crate::types::BatchCreatePrintersRequest,
408    ) -> ClientResult<crate::Response<crate::types::BatchCreatePrintersResponse>> {
409        let url = self.client.url(
410            &format!(
411                "/admin/directory/v1/{}/chrome/printers:batchCreatePrinters",
412                crate::progenitor_support::encode_path(parent),
413            ),
414            None,
415        );
416        self.client
417            .post(
418                &url,
419                crate::Message {
420                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
421                    content_type: Some("application/json".to_string()),
422                },
423            )
424            .await
425    }
426    /**
427     * This function performs a `POST` to the `/admin/directory/v1/{parent}/chrome/printers:batchDeletePrinters` endpoint.
428     *
429     * Deletes printers in batch.
430     *
431     * **Parameters:**
432     *
433     * * `parent: &str` -- Required. The name of the customer. Format: customers/{customer_id}.
434     */
435    pub async fn admin_chrome_printers_batch_delete(
436        &self,
437        parent: &str,
438        body: &crate::types::BatchDeletePrintersRequest,
439    ) -> ClientResult<crate::Response<crate::types::BatchDeletePrintersResponse>> {
440        let url = self.client.url(
441            &format!(
442                "/admin/directory/v1/{}/chrome/printers:batchDeletePrinters",
443                crate::progenitor_support::encode_path(parent),
444            ),
445            None,
446        );
447        self.client
448            .post(
449                &url,
450                crate::Message {
451                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
452                    content_type: Some("application/json".to_string()),
453                },
454            )
455            .await
456    }
457    /**
458     * This function performs a `GET` to the `/admin/directory/v1/{parent}/chrome/printers:listPrinterModels` endpoint.
459     *
460     * Lists the supported printer models.
461     *
462     * **Parameters:**
463     *
464     * * `parent: &str` -- Required. The name of the customer who owns this collection of printers. Format: customers/{customer_id}.
465     * * `filter: &str` -- Filer to list only models by a given manufacturer in format: "manufacturer:Brother". Search syntax is shared between this api and Admin Console printers pages.
466     * * `page_size: i64` -- The maximum number of objects to return. The service may return fewer than this value.
467     * * `page_token: &str` -- A page token, received from a previous call.
468     */
469    pub async fn admin_chrome_printers_list_printer_models(
470        &self,
471        parent: &str,
472        filter: &str,
473        page_size: i64,
474        page_token: &str,
475    ) -> ClientResult<crate::Response<Vec<crate::types::PrinterModel>>> {
476        let mut query_args: Vec<(String, String)> = Default::default();
477        if !filter.is_empty() {
478            query_args.push(("filter".to_string(), filter.to_string()));
479        }
480        if page_size > 0 {
481            query_args.push(("pageSize".to_string(), page_size.to_string()));
482        }
483        if !page_token.is_empty() {
484            query_args.push(("pageToken".to_string(), page_token.to_string()));
485        }
486        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
487        let url = self.client.url(
488            &format!(
489                "/admin/directory/v1/{}/chrome/printers:listPrinterModels?{}",
490                crate::progenitor_support::encode_path(parent),
491                query_
492            ),
493            None,
494        );
495        let resp: crate::Response<crate::types::ListPrinterModelsResponse> = self
496            .client
497            .get(
498                &url,
499                crate::Message {
500                    body: None,
501                    content_type: None,
502                },
503            )
504            .await?;
505
506        // Return our response data.
507        Ok(crate::Response::new(
508            resp.status,
509            resp.headers,
510            resp.body.printer_models.to_vec(),
511        ))
512    }
513    /**
514     * This function performs a `GET` to the `/admin/directory/v1/{parent}/chrome/printers:listPrinterModels` endpoint.
515     *
516     * As opposed to `admin_chrome_printers_list_printer_models`, this function returns all the pages of the request at once.
517     *
518     * Lists the supported printer models.
519     */
520    pub async fn admin_chrome_printers_list_all_printer_models(
521        &self,
522        parent: &str,
523        filter: &str,
524    ) -> ClientResult<crate::Response<Vec<crate::types::PrinterModel>>> {
525        let mut query_args: Vec<(String, String)> = Default::default();
526        if !filter.is_empty() {
527            query_args.push(("filter".to_string(), filter.to_string()));
528        }
529        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
530        let url = self.client.url(
531            &format!(
532                "/admin/directory/v1/{}/chrome/printers:listPrinterModels?{}",
533                crate::progenitor_support::encode_path(parent),
534                query_
535            ),
536            None,
537        );
538        let crate::Response::<crate::types::ListPrinterModelsResponse> {
539            mut status,
540            mut headers,
541            mut body,
542        } = self
543            .client
544            .get(
545                &url,
546                crate::Message {
547                    body: None,
548                    content_type: None,
549                },
550            )
551            .await?;
552
553        let mut printer_models = body.printer_models;
554        let mut page = body.next_page_token;
555
556        // Paginate if we should.
557        while !page.is_empty() {
558            if !url.contains('?') {
559                crate::Response::<crate::types::ListPrinterModelsResponse> {
560                    status,
561                    headers,
562                    body,
563                } = self
564                    .client
565                    .get(
566                        &format!("{}?pageToken={}", url, page),
567                        crate::Message {
568                            body: None,
569                            content_type: None,
570                        },
571                    )
572                    .await?;
573            } else {
574                crate::Response::<crate::types::ListPrinterModelsResponse> {
575                    status,
576                    headers,
577                    body,
578                } = self
579                    .client
580                    .get(
581                        &format!("{}&pageToken={}", url, page),
582                        crate::Message {
583                            body: None,
584                            content_type: None,
585                        },
586                    )
587                    .await?;
588            }
589
590            printer_models.append(&mut body.printer_models);
591
592            if !body.next_page_token.is_empty() && body.next_page_token != page {
593                page = body.next_page_token.to_string();
594            } else {
595                page = "".to_string();
596            }
597        }
598
599        // Return our response data.
600        Ok(crate::Response::new(status, headers, printer_models))
601    }
602}