google_drive/
drives.rs

1use crate::Client;
2use crate::ClientResult;
3
4pub struct Drives {
5    pub client: Client,
6}
7
8impl Drives {
9    #[doc(hidden)]
10    pub fn new(client: Client) -> Self {
11        Drives { client }
12    }
13
14    /**
15     * This function performs a `GET` to the `/drives` endpoint.
16     *
17     * Lists the user's shared drives.
18     *
19     * **Parameters:**
20     *
21     * * `page_size: i64` -- A map of maximum import sizes by MIME type, in bytes.
22     * * `page_token: &str` -- A link to this theme's background image.
23     * * `q: &str` -- A link to this theme's background image.
24     * * `use_domain_admin_access: bool` -- Issue the request as a domain administrator; if set to true, then all shared drives of the domain in which the requester is an administrator are returned.
25     */
26    pub async fn list(
27        &self,
28        page_size: i64,
29        page_token: &str,
30        q: &str,
31        use_domain_admin_access: bool,
32    ) -> ClientResult<crate::Response<Vec<crate::types::Drive>>> {
33        let mut query_args: Vec<(String, String)> = Default::default();
34        if page_size > 0 {
35            query_args.push(("pageSize".to_string(), page_size.to_string()));
36        }
37        if !page_token.is_empty() {
38            query_args.push(("pageToken".to_string(), page_token.to_string()));
39        }
40        if !q.is_empty() {
41            query_args.push(("q".to_string(), q.to_string()));
42        }
43        if use_domain_admin_access {
44            query_args.push((
45                "useDomainAdminAccess".to_string(),
46                use_domain_admin_access.to_string(),
47            ));
48        }
49        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
50        let url = self.client.url(&format!("/drives?{}", query_), None);
51        let resp: crate::Response<crate::types::DriveList> = self
52            .client
53            .get(
54                &url,
55                crate::Message {
56                    body: None,
57                    content_type: None,
58                },
59            )
60            .await?;
61
62        // Return our response data.
63        Ok(crate::Response::new(
64            resp.status,
65            resp.headers,
66            resp.body.drives.to_vec(),
67        ))
68    }
69    /**
70     * This function performs a `GET` to the `/drives` endpoint.
71     *
72     * As opposed to `list`, this function returns all the pages of the request at once.
73     *
74     * Lists the user's shared drives.
75     */
76    pub async fn list_all(
77        &self,
78        q: &str,
79        use_domain_admin_access: bool,
80    ) -> ClientResult<crate::Response<Vec<crate::types::Drive>>> {
81        let mut query_args: Vec<(String, String)> = Default::default();
82        if !q.is_empty() {
83            query_args.push(("q".to_string(), q.to_string()));
84        }
85        if use_domain_admin_access {
86            query_args.push((
87                "useDomainAdminAccess".to_string(),
88                use_domain_admin_access.to_string(),
89            ));
90        }
91        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
92        let url = self.client.url(&format!("/drives?{}", query_), None);
93        let crate::Response::<crate::types::DriveList> {
94            mut status,
95            mut headers,
96            mut body,
97        } = self
98            .client
99            .get(
100                &url,
101                crate::Message {
102                    body: None,
103                    content_type: None,
104                },
105            )
106            .await?;
107
108        let mut drives = body.drives;
109        let mut page = body.next_page_token;
110
111        // Paginate if we should.
112        while !page.is_empty() {
113            if !url.contains('?') {
114                crate::Response::<crate::types::DriveList> {
115                    status,
116                    headers,
117                    body,
118                } = self
119                    .client
120                    .get(
121                        &format!("{}?pageToken={}", url, page),
122                        crate::Message {
123                            body: None,
124                            content_type: None,
125                        },
126                    )
127                    .await?;
128            } else {
129                crate::Response::<crate::types::DriveList> {
130                    status,
131                    headers,
132                    body,
133                } = self
134                    .client
135                    .get(
136                        &format!("{}&pageToken={}", url, page),
137                        crate::Message {
138                            body: None,
139                            content_type: None,
140                        },
141                    )
142                    .await?;
143            }
144
145            drives.append(&mut body.drives);
146
147            if !body.next_page_token.is_empty() && body.next_page_token != page {
148                page = body.next_page_token.to_string();
149            } else {
150                page = "".to_string();
151            }
152        }
153
154        // Return our response data.
155        Ok(crate::Response::new(status, headers, drives))
156    }
157    /**
158     * This function performs a `POST` to the `/drives` endpoint.
159     *
160     * Creates a new shared drive.
161     *
162     * **Parameters:**
163     *
164     * * `request_id: &str` -- An ID, such as a random UUID, which uniquely identifies this user's request for idempotent creation of a shared drive. A repeated request by the same user and with the same request ID will avoid creating duplicates by attempting to create the same shared drive. If the shared drive already exists a 409 error will be returned.
165     */
166    pub async fn create(
167        &self,
168        request_id: &str,
169        body: &crate::types::Drive,
170    ) -> ClientResult<crate::Response<crate::types::Drive>> {
171        let mut query_args: Vec<(String, String)> = Default::default();
172        if !request_id.is_empty() {
173            query_args.push(("requestId".to_string(), request_id.to_string()));
174        }
175        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
176        let url = self.client.url(&format!("/drives?{}", query_), None);
177        self.client
178            .post(
179                &url,
180                crate::Message {
181                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
182                    content_type: Some("application/json".to_string()),
183                },
184            )
185            .await
186    }
187    /**
188     * This function performs a `GET` to the `/drives/{driveId}` endpoint.
189     *
190     * Gets a shared drive's metadata by ID.
191     *
192     * **Parameters:**
193     *
194     * * `drive_id: &str` -- A link to this theme's background image.
195     * * `use_domain_admin_access: bool` -- Issue the request as a domain administrator; if set to true, then the requester will be granted access if they are an administrator of the domain to which the shared drive belongs.
196     */
197    pub async fn get(
198        &self,
199        drive_id: &str,
200        use_domain_admin_access: bool,
201    ) -> ClientResult<crate::Response<crate::types::Drive>> {
202        let mut query_args: Vec<(String, String)> = Default::default();
203        if use_domain_admin_access {
204            query_args.push((
205                "useDomainAdminAccess".to_string(),
206                use_domain_admin_access.to_string(),
207            ));
208        }
209        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
210        let url = self.client.url(
211            &format!(
212                "/drives/{}?{}",
213                crate::progenitor_support::encode_path(drive_id),
214                query_
215            ),
216            None,
217        );
218        self.client
219            .get(
220                &url,
221                crate::Message {
222                    body: None,
223                    content_type: None,
224                },
225            )
226            .await
227    }
228    /**
229     * This function performs a `DELETE` to the `/drives/{driveId}` endpoint.
230     *
231     * Permanently deletes a shared drive for which the user is an organizer. The shared drive cannot contain any untrashed items.
232     *
233     * **Parameters:**
234     *
235     * * `drive_id: &str` -- A link to this theme's background image.
236     */
237    pub async fn delete(&self, drive_id: &str) -> ClientResult<crate::Response<()>> {
238        let url = self.client.url(
239            &format!(
240                "/drives/{}",
241                crate::progenitor_support::encode_path(drive_id),
242            ),
243            None,
244        );
245        self.client
246            .delete(
247                &url,
248                crate::Message {
249                    body: None,
250                    content_type: None,
251                },
252            )
253            .await
254    }
255    /**
256     * This function performs a `PATCH` to the `/drives/{driveId}` endpoint.
257     *
258     * Updates the metadate for a shared drive.
259     *
260     * **Parameters:**
261     *
262     * * `drive_id: &str` -- A link to this theme's background image.
263     * * `use_domain_admin_access: bool` -- Issue the request as a domain administrator; if set to true, then the requester will be granted access if they are an administrator of the domain to which the shared drive belongs.
264     */
265    pub async fn update(
266        &self,
267        drive_id: &str,
268        use_domain_admin_access: bool,
269        body: &crate::types::Drive,
270    ) -> ClientResult<crate::Response<crate::types::Drive>> {
271        let mut query_args: Vec<(String, String)> = Default::default();
272        if use_domain_admin_access {
273            query_args.push((
274                "useDomainAdminAccess".to_string(),
275                use_domain_admin_access.to_string(),
276            ));
277        }
278        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
279        let url = self.client.url(
280            &format!(
281                "/drives/{}?{}",
282                crate::progenitor_support::encode_path(drive_id),
283                query_
284            ),
285            None,
286        );
287        self.client
288            .patch(
289                &url,
290                crate::Message {
291                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
292                    content_type: Some("application/json".to_string()),
293                },
294            )
295            .await
296    }
297    /**
298     * This function performs a `POST` to the `/drives/{driveId}/hide` endpoint.
299     *
300     * Hides a shared drive from the default view.
301     *
302     * **Parameters:**
303     *
304     * * `drive_id: &str` -- A link to this theme's background image.
305     */
306    pub async fn hide(&self, drive_id: &str) -> ClientResult<crate::Response<crate::types::Drive>> {
307        let url = self.client.url(
308            &format!(
309                "/drives/{}/hide",
310                crate::progenitor_support::encode_path(drive_id),
311            ),
312            None,
313        );
314        self.client
315            .post(
316                &url,
317                crate::Message {
318                    body: None,
319                    content_type: None,
320                },
321            )
322            .await
323    }
324    /**
325     * This function performs a `POST` to the `/drives/{driveId}/unhide` endpoint.
326     *
327     * Restores a shared drive to the default view.
328     *
329     * **Parameters:**
330     *
331     * * `drive_id: &str` -- A link to this theme's background image.
332     */
333    pub async fn unhide(
334        &self,
335        drive_id: &str,
336    ) -> ClientResult<crate::Response<crate::types::Drive>> {
337        let url = self.client.url(
338            &format!(
339                "/drives/{}/unhide",
340                crate::progenitor_support::encode_path(drive_id),
341            ),
342            None,
343        );
344        self.client
345            .post(
346                &url,
347                crate::Message {
348                    body: None,
349                    content_type: None,
350                },
351            )
352            .await
353    }
354}