gsuite_api/
chromeosdevices.rs

1use crate::Client;
2use crate::ClientResult;
3
4pub struct Chromeosdevices {
5    pub client: Client,
6}
7
8impl Chromeosdevices {
9    #[doc(hidden)]
10    pub fn new(client: Client) -> Self {
11        Chromeosdevices { client }
12    }
13
14    /**
15     * This function performs a `GET` to the `/admin/directory/v1/customer/{customerId}/devices/chromeos` endpoint.
16     *
17     * Retrieves a paginated list of Chrome OS devices within an account.
18     *
19     * **Parameters:**
20     *
21     * * `customer_id: &str` -- The unique ID for the customer's Google Workspace account. As an account administrator, you can also use the `my_customer` alias to represent your account's `customerId`. The `customerId` is also returned as part of the [Users resource](/admin-sdk/directory/v1/reference/users).
22     * * `max_results: i64` -- Maximum number of results to return.
23     * * `order_by: crate::types::OrderBy` -- Device property to use for sorting results.
24     * * `org_unit_path: &str` -- The full path of the organizational unit or its unique ID.
25     * * `page_token: &str` -- The `pageToken` query parameter is used to request the next page of query results. The follow-on request's `pageToken` query parameter is the `nextPageToken` from your previous response.
26     * * `projection: crate::types::Projection` -- Restrict information returned to a set of selected fields.
27     * * `query: &str` -- Search string in the format given at http://support.google.com/chromeos/a/bin/answer.py?answer=1698333.
28     * * `sort_order: crate::types::SortOrder` -- Whether to return results in ascending or descending order. Must be used with the `orderBy` parameter.
29     */
30    pub async fn list(
31        &self,
32        customer_id: &str,
33        max_results: i64,
34        order_by: crate::types::OrderBy,
35        org_unit_path: &str,
36        page_token: &str,
37        projection: crate::types::Projection,
38        query: &str,
39        sort_order: crate::types::SortOrder,
40    ) -> ClientResult<crate::Response<Vec<crate::types::ChromeOsDevice>>> {
41        let mut query_args: Vec<(String, String)> = Default::default();
42        if max_results > 0 {
43            query_args.push(("maxResults".to_string(), max_results.to_string()));
44        }
45        if !order_by.to_string().is_empty() {
46            query_args.push(("orderBy".to_string(), order_by.to_string()));
47        }
48        if !org_unit_path.is_empty() {
49            query_args.push(("orgUnitPath".to_string(), org_unit_path.to_string()));
50        }
51        if !page_token.is_empty() {
52            query_args.push(("pageToken".to_string(), page_token.to_string()));
53        }
54        if !projection.to_string().is_empty() {
55            query_args.push(("projection".to_string(), projection.to_string()));
56        }
57        if !query.is_empty() {
58            query_args.push(("query".to_string(), query.to_string()));
59        }
60        if !sort_order.to_string().is_empty() {
61            query_args.push(("sortOrder".to_string(), sort_order.to_string()));
62        }
63        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
64        let url = self.client.url(
65            &format!(
66                "/admin/directory/v1/customer/{}/devices/chromeos?{}",
67                crate::progenitor_support::encode_path(customer_id),
68                query_
69            ),
70            None,
71        );
72        let resp: crate::Response<crate::types::ChromeOsDevices> = self
73            .client
74            .get(
75                &url,
76                crate::Message {
77                    body: None,
78                    content_type: None,
79                },
80            )
81            .await?;
82
83        // Return our response data.
84        Ok(crate::Response::new(
85            resp.status,
86            resp.headers,
87            resp.body.chromeosdevices.to_vec(),
88        ))
89    }
90    /**
91     * This function performs a `GET` to the `/admin/directory/v1/customer/{customerId}/devices/chromeos` endpoint.
92     *
93     * As opposed to `list`, this function returns all the pages of the request at once.
94     *
95     * Retrieves a paginated list of Chrome OS devices within an account.
96     */
97    pub async fn list_all(
98        &self,
99        customer_id: &str,
100        order_by: crate::types::OrderBy,
101        org_unit_path: &str,
102        projection: crate::types::Projection,
103        query: &str,
104        sort_order: crate::types::SortOrder,
105    ) -> ClientResult<crate::Response<Vec<crate::types::ChromeOsDevice>>> {
106        let mut query_args: Vec<(String, String)> = Default::default();
107        if !order_by.to_string().is_empty() {
108            query_args.push(("orderBy".to_string(), order_by.to_string()));
109        }
110        if !org_unit_path.is_empty() {
111            query_args.push(("orgUnitPath".to_string(), org_unit_path.to_string()));
112        }
113        if !projection.to_string().is_empty() {
114            query_args.push(("projection".to_string(), projection.to_string()));
115        }
116        if !query.is_empty() {
117            query_args.push(("query".to_string(), query.to_string()));
118        }
119        if !sort_order.to_string().is_empty() {
120            query_args.push(("sortOrder".to_string(), sort_order.to_string()));
121        }
122        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
123        let url = self.client.url(
124            &format!(
125                "/admin/directory/v1/customer/{}/devices/chromeos?{}",
126                crate::progenitor_support::encode_path(customer_id),
127                query_
128            ),
129            None,
130        );
131        let crate::Response::<crate::types::ChromeOsDevices> {
132            mut status,
133            mut headers,
134            mut body,
135        } = self
136            .client
137            .get(
138                &url,
139                crate::Message {
140                    body: None,
141                    content_type: None,
142                },
143            )
144            .await?;
145
146        let mut chromeosdevices = body.chromeosdevices;
147        let mut page = body.next_page_token;
148
149        // Paginate if we should.
150        while !page.is_empty() {
151            if !url.contains('?') {
152                crate::Response::<crate::types::ChromeOsDevices> {
153                    status,
154                    headers,
155                    body,
156                } = self
157                    .client
158                    .get(
159                        &format!("{}?pageToken={}", url, page),
160                        crate::Message {
161                            body: None,
162                            content_type: None,
163                        },
164                    )
165                    .await?;
166            } else {
167                crate::Response::<crate::types::ChromeOsDevices> {
168                    status,
169                    headers,
170                    body,
171                } = self
172                    .client
173                    .get(
174                        &format!("{}&pageToken={}", url, page),
175                        crate::Message {
176                            body: None,
177                            content_type: None,
178                        },
179                    )
180                    .await?;
181            }
182
183            chromeosdevices.append(&mut body.chromeosdevices);
184
185            if !body.next_page_token.is_empty() && body.next_page_token != page {
186                page = body.next_page_token.to_string();
187            } else {
188                page = "".to_string();
189            }
190        }
191
192        // Return our response data.
193        Ok(crate::Response::new(status, headers, chromeosdevices))
194    }
195    /**
196     * This function performs a `POST` to the `/admin/directory/v1/customer/{customerId}/devices/chromeos/moveDevicesToOu` endpoint.
197     *
198     * Moves or inserts multiple Chrome OS devices to an organizational unit. You can move up to 50 devices at once.
199     *
200     * **Parameters:**
201     *
202     * * `customer_id: &str` -- Immutable ID of the Google Workspace account.
203     * * `org_unit_path: &str` -- Full path of the target organizational unit or its ID.
204     */
205    pub async fn move_devices_ou(
206        &self,
207        customer_id: &str,
208        org_unit_path: &str,
209        body: &crate::types::ChromeOsMoveDevicesOu,
210    ) -> ClientResult<crate::Response<()>> {
211        let mut query_args: Vec<(String, String)> = Default::default();
212        if !org_unit_path.is_empty() {
213            query_args.push(("orgUnitPath".to_string(), org_unit_path.to_string()));
214        }
215        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
216        let url = self.client.url(
217            &format!(
218                "/admin/directory/v1/customer/{}/devices/chromeos/moveDevicesToOu?{}",
219                crate::progenitor_support::encode_path(customer_id),
220                query_
221            ),
222            None,
223        );
224        self.client
225            .post(
226                &url,
227                crate::Message {
228                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
229                    content_type: Some("application/json".to_string()),
230                },
231            )
232            .await
233    }
234    /**
235     * This function performs a `GET` to the `/admin/directory/v1/customer/{customerId}/devices/chromeos/{deviceId}` endpoint.
236     *
237     * Retrieves a Chrome OS device's properties.
238     *
239     * **Parameters:**
240     *
241     * * `customer_id: &str` -- The unique ID for the customer's Google Workspace account. As an account administrator, you can also use the `my_customer` alias to represent your account's `customerId`. The `customerId` is also returned as part of the [Users resource](/admin-sdk/directory/v1/reference/users).
242     * * `device_id: &str` -- The unique ID of the device. The `deviceId`s are returned in the response from the [chromeosdevices.list](/admin-sdk/directory/v1/reference/chromeosdevices/list) method.
243     * * `projection: crate::types::Projection` -- Determines whether the response contains the full list of properties or only a subset.
244     */
245    pub async fn get(
246        &self,
247        customer_id: &str,
248        device_id: &str,
249        projection: crate::types::Projection,
250    ) -> ClientResult<crate::Response<crate::types::ChromeOsDevice>> {
251        let mut query_args: Vec<(String, String)> = Default::default();
252        if !projection.to_string().is_empty() {
253            query_args.push(("projection".to_string(), projection.to_string()));
254        }
255        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
256        let url = self.client.url(
257            &format!(
258                "/admin/directory/v1/customer/{}/devices/chromeos/{}?{}",
259                crate::progenitor_support::encode_path(customer_id),
260                crate::progenitor_support::encode_path(device_id),
261                query_
262            ),
263            None,
264        );
265        self.client
266            .get(
267                &url,
268                crate::Message {
269                    body: None,
270                    content_type: None,
271                },
272            )
273            .await
274    }
275    /**
276     * This function performs a `PUT` to the `/admin/directory/v1/customer/{customerId}/devices/chromeos/{deviceId}` endpoint.
277     *
278     * Updates a device's updatable properties, such as `annotatedUser`, `annotatedLocation`, `notes`, `orgUnitPath`, or `annotatedAssetId`.
279     *
280     * **Parameters:**
281     *
282     * * `customer_id: &str` -- The unique ID for the customer's Google Workspace account. As an account administrator, you can also use the `my_customer` alias to represent your account's `customerId`. The `customerId` is also returned as part of the [Users resource](/admin-sdk/directory/v1/reference/users).
283     * * `device_id: &str` -- The unique ID of the device. The `deviceId`s are returned in the response from the [chromeosdevices.list](/admin-sdk/v1/reference/chromeosdevices/list) method.
284     * * `projection: crate::types::Projection` -- Restrict information returned to a set of selected fields.
285     */
286    pub async fn update(
287        &self,
288        customer_id: &str,
289        device_id: &str,
290        projection: crate::types::Projection,
291        body: &crate::types::ChromeOsDevice,
292    ) -> ClientResult<crate::Response<crate::types::ChromeOsDevice>> {
293        let mut query_args: Vec<(String, String)> = Default::default();
294        if !projection.to_string().is_empty() {
295            query_args.push(("projection".to_string(), projection.to_string()));
296        }
297        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
298        let url = self.client.url(
299            &format!(
300                "/admin/directory/v1/customer/{}/devices/chromeos/{}?{}",
301                crate::progenitor_support::encode_path(customer_id),
302                crate::progenitor_support::encode_path(device_id),
303                query_
304            ),
305            None,
306        );
307        self.client
308            .put(
309                &url,
310                crate::Message {
311                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
312                    content_type: Some("application/json".to_string()),
313                },
314            )
315            .await
316    }
317    /**
318     * This function performs a `PATCH` to the `/admin/directory/v1/customer/{customerId}/devices/chromeos/{deviceId}` endpoint.
319     *
320     * Updates a device's updatable properties, such as `annotatedUser`, `annotatedLocation`, `notes`, `orgUnitPath`, or `annotatedAssetId`. This method supports [patch semantics](/admin-sdk/directory/v1/guides/performance#patch).
321     *
322     * **Parameters:**
323     *
324     * * `customer_id: &str` -- The unique ID for the customer's Google Workspace account. As an account administrator, you can also use the `my_customer` alias to represent your account's `customerId`. The `customerId` is also returned as part of the [Users resource](/admin-sdk/directory/v1/reference/users).
325     * * `device_id: &str` -- The unique ID of the device. The `deviceId`s are returned in the response from the [chromeosdevices.list](/admin-sdk/v1/reference/chromeosdevices/list) method.
326     * * `projection: crate::types::Projection` -- Restrict information returned to a set of selected fields.
327     */
328    pub async fn patch(
329        &self,
330        customer_id: &str,
331        device_id: &str,
332        projection: crate::types::Projection,
333        body: &crate::types::ChromeOsDevice,
334    ) -> ClientResult<crate::Response<crate::types::ChromeOsDevice>> {
335        let mut query_args: Vec<(String, String)> = Default::default();
336        if !projection.to_string().is_empty() {
337            query_args.push(("projection".to_string(), projection.to_string()));
338        }
339        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
340        let url = self.client.url(
341            &format!(
342                "/admin/directory/v1/customer/{}/devices/chromeos/{}?{}",
343                crate::progenitor_support::encode_path(customer_id),
344                crate::progenitor_support::encode_path(device_id),
345                query_
346            ),
347            None,
348        );
349        self.client
350            .patch(
351                &url,
352                crate::Message {
353                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
354                    content_type: Some("application/json".to_string()),
355                },
356            )
357            .await
358    }
359    /**
360     * This function performs a `POST` to the `/admin/directory/v1/customer/{customerId}/devices/chromeos/{resourceId}/action` endpoint.
361     *
362     * Takes an action that affects a Chrome OS Device. This includes deprovisioning, disabling, and re-enabling devices. *Warning:* * Deprovisioning a device will stop device policy syncing and remove device-level printers. After a device is deprovisioned, it must be wiped before it can be re-enrolled. * Lost or stolen devices should use the disable action. * Re-enabling a disabled device will consume a device license. If you do not have sufficient licenses available when completing the re-enable action, you will receive an error. For more information about deprovisioning and disabling devices, visit the [help center](https://support.google.com/chrome/a/answer/3523633).
363     *
364     * **Parameters:**
365     *
366     * * `customer_id: &str` -- The unique ID for the customer's Google Workspace account. As an account administrator, you can also use the `my_customer` alias to represent your account's `customerId`. The `customerId` is also returned as part of the [Users resource](/admin-sdk/directory/v1/reference/users).
367     * * `resource_id: &str` -- The unique ID of the device. The `resourceId`s are returned in the response from the [chromeosdevices.list](/admin-sdk/directory/v1/reference/chromeosdevices/list) method.
368     */
369    pub async fn action(
370        &self,
371        customer_id: &str,
372        resource_id: &str,
373        body: &crate::types::ChromeOsDeviceAction,
374    ) -> ClientResult<crate::Response<()>> {
375        let url = self.client.url(
376            &format!(
377                "/admin/directory/v1/customer/{}/devices/chromeos/{}/action",
378                crate::progenitor_support::encode_path(customer_id),
379                crate::progenitor_support::encode_path(resource_id),
380            ),
381            None,
382        );
383        self.client
384            .post(
385                &url,
386                crate::Message {
387                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
388                    content_type: Some("application/json".to_string()),
389                },
390            )
391            .await
392    }
393}