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 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 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 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 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 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 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 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 Ok(crate::Response::new(
266 resp.status,
267 resp.headers,
268 resp.body.printers.to_vec(),
269 ))
270 }
271 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 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 Ok(crate::Response::new(status, headers, printers))
363 }
364 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 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 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 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 Ok(crate::Response::new(
508 resp.status,
509 resp.headers,
510 resp.body.printer_models.to_vec(),
511 ))
512 }
513 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 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 Ok(crate::Response::new(status, headers, printer_models))
601 }
602}