google_drive/
replies.rs

1use crate::Client;
2use crate::ClientResult;
3
4pub struct Replies {
5    pub client: Client,
6}
7
8impl Replies {
9    #[doc(hidden)]
10    pub fn new(client: Client) -> Self {
11        Replies { client }
12    }
13
14    /**
15     * This function performs a `GET` to the `/files/{fileId}/comments/{commentId}/replies` endpoint.
16     *
17     * Lists a comment's replies.
18     *
19     * **Parameters:**
20     *
21     * * `file_id: &str` -- A link to this theme's background image.
22     * * `comment_id: &str` -- A link to this theme's background image.
23     * * `include_deleted: bool` -- Whether to include deleted replies. Deleted replies will not include their original content.
24     * * `page_size: i64` -- A map of maximum import sizes by MIME type, in bytes.
25     * * `page_token: &str` -- The token for continuing a previous list request on the next page. This should be set to the value of 'nextPageToken' from the previous response.
26     */
27    pub async fn list(
28        &self,
29        file_id: &str,
30        comment_id: &str,
31        include_deleted: bool,
32        page_size: i64,
33        page_token: &str,
34    ) -> ClientResult<crate::Response<Vec<crate::types::Reply>>> {
35        let mut query_args: Vec<(String, String)> = Default::default();
36        if include_deleted {
37            query_args.push(("includeDeleted".to_string(), include_deleted.to_string()));
38        }
39        if page_size > 0 {
40            query_args.push(("pageSize".to_string(), page_size.to_string()));
41        }
42        if !page_token.is_empty() {
43            query_args.push(("pageToken".to_string(), page_token.to_string()));
44        }
45        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
46        let url = self.client.url(
47            &format!(
48                "/files/{}/comments/{}/replies?{}",
49                crate::progenitor_support::encode_path(file_id),
50                crate::progenitor_support::encode_path(comment_id),
51                query_
52            ),
53            None,
54        );
55        let resp: crate::Response<crate::types::ReplyList> = self
56            .client
57            .get(
58                &url,
59                crate::Message {
60                    body: None,
61                    content_type: None,
62                },
63            )
64            .await?;
65
66        // Return our response data.
67        Ok(crate::Response::new(
68            resp.status,
69            resp.headers,
70            resp.body.replies.to_vec(),
71        ))
72    }
73    /**
74     * This function performs a `GET` to the `/files/{fileId}/comments/{commentId}/replies` endpoint.
75     *
76     * As opposed to `list`, this function returns all the pages of the request at once.
77     *
78     * Lists a comment's replies.
79     */
80    pub async fn list_all(
81        &self,
82        file_id: &str,
83        comment_id: &str,
84        include_deleted: bool,
85    ) -> ClientResult<crate::Response<Vec<crate::types::Reply>>> {
86        let mut query_args: Vec<(String, String)> = Default::default();
87        if include_deleted {
88            query_args.push(("includeDeleted".to_string(), include_deleted.to_string()));
89        }
90        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
91        let url = self.client.url(
92            &format!(
93                "/files/{}/comments/{}/replies?{}",
94                crate::progenitor_support::encode_path(file_id),
95                crate::progenitor_support::encode_path(comment_id),
96                query_
97            ),
98            None,
99        );
100        let crate::Response::<crate::types::ReplyList> {
101            mut status,
102            mut headers,
103            mut body,
104        } = self
105            .client
106            .get(
107                &url,
108                crate::Message {
109                    body: None,
110                    content_type: None,
111                },
112            )
113            .await?;
114
115        let mut replies = body.replies;
116        let mut page = body.next_page_token;
117
118        // Paginate if we should.
119        while !page.is_empty() {
120            if !url.contains('?') {
121                crate::Response::<crate::types::ReplyList> {
122                    status,
123                    headers,
124                    body,
125                } = self
126                    .client
127                    .get(
128                        &format!("{}?pageToken={}", url, page),
129                        crate::Message {
130                            body: None,
131                            content_type: None,
132                        },
133                    )
134                    .await?;
135            } else {
136                crate::Response::<crate::types::ReplyList> {
137                    status,
138                    headers,
139                    body,
140                } = self
141                    .client
142                    .get(
143                        &format!("{}&pageToken={}", url, page),
144                        crate::Message {
145                            body: None,
146                            content_type: None,
147                        },
148                    )
149                    .await?;
150            }
151
152            replies.append(&mut body.replies);
153
154            if !body.next_page_token.is_empty() && body.next_page_token != page {
155                page = body.next_page_token.to_string();
156            } else {
157                page = "".to_string();
158            }
159        }
160
161        // Return our response data.
162        Ok(crate::Response::new(status, headers, replies))
163    }
164    /**
165     * This function performs a `POST` to the `/files/{fileId}/comments/{commentId}/replies` endpoint.
166     *
167     * Creates a new reply to a comment.
168     *
169     * **Parameters:**
170     *
171     * * `file_id: &str` -- A link to this theme's background image.
172     * * `comment_id: &str` -- A link to this theme's background image.
173     */
174    pub async fn create(
175        &self,
176        file_id: &str,
177        comment_id: &str,
178        body: &crate::types::Reply,
179    ) -> ClientResult<crate::Response<crate::types::Reply>> {
180        let url = self.client.url(
181            &format!(
182                "/files/{}/comments/{}/replies",
183                crate::progenitor_support::encode_path(file_id),
184                crate::progenitor_support::encode_path(comment_id),
185            ),
186            None,
187        );
188        self.client
189            .post(
190                &url,
191                crate::Message {
192                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
193                    content_type: Some("application/json".to_string()),
194                },
195            )
196            .await
197    }
198    /**
199     * This function performs a `GET` to the `/files/{fileId}/comments/{commentId}/replies/{replyId}` endpoint.
200     *
201     * Gets a reply by ID.
202     *
203     * **Parameters:**
204     *
205     * * `file_id: &str` -- A link to this theme's background image.
206     * * `comment_id: &str` -- A link to this theme's background image.
207     * * `reply_id: &str` -- A link to this theme's background image.
208     * * `include_deleted: bool` -- Whether to return deleted replies. Deleted replies will not include their original content.
209     */
210    pub async fn get(
211        &self,
212        file_id: &str,
213        comment_id: &str,
214        reply_id: &str,
215        include_deleted: bool,
216    ) -> ClientResult<crate::Response<crate::types::Reply>> {
217        let mut query_args: Vec<(String, String)> = Default::default();
218        if include_deleted {
219            query_args.push(("includeDeleted".to_string(), include_deleted.to_string()));
220        }
221        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
222        let url = self.client.url(
223            &format!(
224                "/files/{}/comments/{}/replies/{}?{}",
225                crate::progenitor_support::encode_path(file_id),
226                crate::progenitor_support::encode_path(comment_id),
227                crate::progenitor_support::encode_path(reply_id),
228                query_
229            ),
230            None,
231        );
232        self.client
233            .get(
234                &url,
235                crate::Message {
236                    body: None,
237                    content_type: None,
238                },
239            )
240            .await
241    }
242    /**
243     * This function performs a `DELETE` to the `/files/{fileId}/comments/{commentId}/replies/{replyId}` endpoint.
244     *
245     * Deletes a reply.
246     *
247     * **Parameters:**
248     *
249     * * `file_id: &str` -- A link to this theme's background image.
250     * * `comment_id: &str` -- A link to this theme's background image.
251     * * `reply_id: &str` -- A link to this theme's background image.
252     */
253    pub async fn delete(
254        &self,
255        file_id: &str,
256        comment_id: &str,
257        reply_id: &str,
258    ) -> ClientResult<crate::Response<()>> {
259        let url = self.client.url(
260            &format!(
261                "/files/{}/comments/{}/replies/{}",
262                crate::progenitor_support::encode_path(file_id),
263                crate::progenitor_support::encode_path(comment_id),
264                crate::progenitor_support::encode_path(reply_id),
265            ),
266            None,
267        );
268        self.client
269            .delete(
270                &url,
271                crate::Message {
272                    body: None,
273                    content_type: None,
274                },
275            )
276            .await
277    }
278    /**
279     * This function performs a `PATCH` to the `/files/{fileId}/comments/{commentId}/replies/{replyId}` endpoint.
280     *
281     * Updates a reply with patch semantics.
282     *
283     * **Parameters:**
284     *
285     * * `file_id: &str` -- A link to this theme's background image.
286     * * `comment_id: &str` -- A link to this theme's background image.
287     * * `reply_id: &str` -- A link to this theme's background image.
288     */
289    pub async fn update(
290        &self,
291        file_id: &str,
292        comment_id: &str,
293        reply_id: &str,
294        body: &crate::types::Reply,
295    ) -> ClientResult<crate::Response<crate::types::Reply>> {
296        let url = self.client.url(
297            &format!(
298                "/files/{}/comments/{}/replies/{}",
299                crate::progenitor_support::encode_path(file_id),
300                crate::progenitor_support::encode_path(comment_id),
301                crate::progenitor_support::encode_path(reply_id),
302            ),
303            None,
304        );
305        self.client
306            .patch(
307                &url,
308                crate::Message {
309                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
310                    content_type: Some("application/json".to_string()),
311                },
312            )
313            .await
314    }
315}