1use crate::Client;
2use crate::ClientResult;
3
4pub struct Changes {
5 pub client: Client,
6}
7
8impl Changes {
9 #[doc(hidden)]
10 pub fn new(client: Client) -> Self {
11 Changes { client }
12 }
13
14 pub async fn list(
36 &self,
37 page_token: &str,
38 drive_id: &str,
39 include_corpus_removals: bool,
40 include_items_from_all_drives: bool,
41 include_permissions_for_view: &str,
42 include_removed: bool,
43 include_team_drive_items: bool,
44 page_size: i64,
45 restrict_to_my_drive: bool,
46 spaces: &str,
47 supports_all_drives: bool,
48 supports_team_drives: bool,
49 team_drive_id: &str,
50 ) -> ClientResult<crate::Response<Vec<crate::types::Change>>> {
51 let mut query_args: Vec<(String, String)> = Default::default();
52 if !drive_id.is_empty() {
53 query_args.push(("driveId".to_string(), drive_id.to_string()));
54 }
55 if include_corpus_removals {
56 query_args.push((
57 "includeCorpusRemovals".to_string(),
58 include_corpus_removals.to_string(),
59 ));
60 }
61 if include_items_from_all_drives {
62 query_args.push((
63 "includeItemsFromAllDrives".to_string(),
64 include_items_from_all_drives.to_string(),
65 ));
66 }
67 if !include_permissions_for_view.is_empty() {
68 query_args.push((
69 "includePermissionsForView".to_string(),
70 include_permissions_for_view.to_string(),
71 ));
72 }
73 if include_removed {
74 query_args.push(("includeRemoved".to_string(), include_removed.to_string()));
75 }
76 if include_team_drive_items {
77 query_args.push((
78 "includeTeamDriveItems".to_string(),
79 include_team_drive_items.to_string(),
80 ));
81 }
82 if page_size > 0 {
83 query_args.push(("pageSize".to_string(), page_size.to_string()));
84 }
85 if !page_token.is_empty() {
86 query_args.push(("pageToken".to_string(), page_token.to_string()));
87 }
88 if restrict_to_my_drive {
89 query_args.push((
90 "restrictToMyDrive".to_string(),
91 restrict_to_my_drive.to_string(),
92 ));
93 }
94 if !spaces.is_empty() {
95 query_args.push(("spaces".to_string(), spaces.to_string()));
96 }
97 if supports_all_drives {
98 query_args.push((
99 "supportsAllDrives".to_string(),
100 supports_all_drives.to_string(),
101 ));
102 }
103 if supports_team_drives {
104 query_args.push((
105 "supportsTeamDrives".to_string(),
106 supports_team_drives.to_string(),
107 ));
108 }
109 if !team_drive_id.is_empty() {
110 query_args.push(("teamDriveId".to_string(), team_drive_id.to_string()));
111 }
112 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
113 let url = self.client.url(&format!("/changes?{}", query_), None);
114 let resp: crate::Response<crate::types::ChangeList> = self
115 .client
116 .get(
117 &url,
118 crate::Message {
119 body: None,
120 content_type: None,
121 },
122 )
123 .await?;
124
125 Ok(crate::Response::new(
127 resp.status,
128 resp.headers,
129 resp.body.changes.to_vec(),
130 ))
131 }
132 pub async fn list_all(
140 &self,
141 drive_id: &str,
142 include_corpus_removals: bool,
143 include_items_from_all_drives: bool,
144 include_permissions_for_view: &str,
145 include_removed: bool,
146 include_team_drive_items: bool,
147 restrict_to_my_drive: bool,
148 spaces: &str,
149 supports_all_drives: bool,
150 supports_team_drives: bool,
151 team_drive_id: &str,
152 ) -> ClientResult<crate::Response<Vec<crate::types::Change>>> {
153 let mut query_args: Vec<(String, String)> = Default::default();
154 if !drive_id.is_empty() {
155 query_args.push(("driveId".to_string(), drive_id.to_string()));
156 }
157 if include_corpus_removals {
158 query_args.push((
159 "includeCorpusRemovals".to_string(),
160 include_corpus_removals.to_string(),
161 ));
162 }
163 if include_items_from_all_drives {
164 query_args.push((
165 "includeItemsFromAllDrives".to_string(),
166 include_items_from_all_drives.to_string(),
167 ));
168 }
169 if !include_permissions_for_view.is_empty() {
170 query_args.push((
171 "includePermissionsForView".to_string(),
172 include_permissions_for_view.to_string(),
173 ));
174 }
175 if include_removed {
176 query_args.push(("includeRemoved".to_string(), include_removed.to_string()));
177 }
178 if include_team_drive_items {
179 query_args.push((
180 "includeTeamDriveItems".to_string(),
181 include_team_drive_items.to_string(),
182 ));
183 }
184 if restrict_to_my_drive {
185 query_args.push((
186 "restrictToMyDrive".to_string(),
187 restrict_to_my_drive.to_string(),
188 ));
189 }
190 if !spaces.is_empty() {
191 query_args.push(("spaces".to_string(), spaces.to_string()));
192 }
193 if supports_all_drives {
194 query_args.push((
195 "supportsAllDrives".to_string(),
196 supports_all_drives.to_string(),
197 ));
198 }
199 if supports_team_drives {
200 query_args.push((
201 "supportsTeamDrives".to_string(),
202 supports_team_drives.to_string(),
203 ));
204 }
205 if !team_drive_id.is_empty() {
206 query_args.push(("teamDriveId".to_string(), team_drive_id.to_string()));
207 }
208 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
209 let url = self.client.url(&format!("/changes?{}", query_), None);
210 let crate::Response::<crate::types::ChangeList> {
211 mut status,
212 mut headers,
213 mut body,
214 } = self
215 .client
216 .get(
217 &url,
218 crate::Message {
219 body: None,
220 content_type: None,
221 },
222 )
223 .await?;
224
225 let mut changes = body.changes;
226 let mut page = body.next_page_token;
227
228 while !page.is_empty() {
230 if !url.contains('?') {
231 crate::Response::<crate::types::ChangeList> {
232 status,
233 headers,
234 body,
235 } = self
236 .client
237 .get(
238 &format!("{}?pageToken={}", url, page),
239 crate::Message {
240 body: None,
241 content_type: None,
242 },
243 )
244 .await?;
245 } else {
246 crate::Response::<crate::types::ChangeList> {
247 status,
248 headers,
249 body,
250 } = self
251 .client
252 .get(
253 &format!("{}&pageToken={}", url, page),
254 crate::Message {
255 body: None,
256 content_type: None,
257 },
258 )
259 .await?;
260 }
261
262 changes.append(&mut body.changes);
263
264 if !body.next_page_token.is_empty() && body.next_page_token != page {
265 page = body.next_page_token.to_string();
266 } else {
267 page = "".to_string();
268 }
269 }
270
271 Ok(crate::Response::new(status, headers, changes))
273 }
274 pub async fn get_start_page_token(
287 &self,
288 drive_id: &str,
289 supports_all_drives: bool,
290 supports_team_drives: bool,
291 team_drive_id: &str,
292 ) -> ClientResult<crate::Response<crate::types::StartPageToken>> {
293 let mut query_args: Vec<(String, String)> = Default::default();
294 if !drive_id.is_empty() {
295 query_args.push(("driveId".to_string(), drive_id.to_string()));
296 }
297 if supports_all_drives {
298 query_args.push((
299 "supportsAllDrives".to_string(),
300 supports_all_drives.to_string(),
301 ));
302 }
303 if supports_team_drives {
304 query_args.push((
305 "supportsTeamDrives".to_string(),
306 supports_team_drives.to_string(),
307 ));
308 }
309 if !team_drive_id.is_empty() {
310 query_args.push(("teamDriveId".to_string(), team_drive_id.to_string()));
311 }
312 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
313 let url = self
314 .client
315 .url(&format!("/changes/startPageToken?{}", query_), None);
316 self.client
317 .get(
318 &url,
319 crate::Message {
320 body: None,
321 content_type: None,
322 },
323 )
324 .await
325 }
326 pub async fn watch(
348 &self,
349 page_token: &str,
350 drive_id: &str,
351 include_corpus_removals: bool,
352 include_items_from_all_drives: bool,
353 include_permissions_for_view: &str,
354 include_removed: bool,
355 include_team_drive_items: bool,
356 page_size: i64,
357 restrict_to_my_drive: bool,
358 spaces: &str,
359 supports_all_drives: bool,
360 supports_team_drives: bool,
361 team_drive_id: &str,
362 body: &crate::types::Channel,
363 ) -> ClientResult<crate::Response<crate::types::Channel>> {
364 let mut query_args: Vec<(String, String)> = Default::default();
365 if !drive_id.is_empty() {
366 query_args.push(("driveId".to_string(), drive_id.to_string()));
367 }
368 if include_corpus_removals {
369 query_args.push((
370 "includeCorpusRemovals".to_string(),
371 include_corpus_removals.to_string(),
372 ));
373 }
374 if include_items_from_all_drives {
375 query_args.push((
376 "includeItemsFromAllDrives".to_string(),
377 include_items_from_all_drives.to_string(),
378 ));
379 }
380 if !include_permissions_for_view.is_empty() {
381 query_args.push((
382 "includePermissionsForView".to_string(),
383 include_permissions_for_view.to_string(),
384 ));
385 }
386 if include_removed {
387 query_args.push(("includeRemoved".to_string(), include_removed.to_string()));
388 }
389 if include_team_drive_items {
390 query_args.push((
391 "includeTeamDriveItems".to_string(),
392 include_team_drive_items.to_string(),
393 ));
394 }
395 if page_size > 0 {
396 query_args.push(("pageSize".to_string(), page_size.to_string()));
397 }
398 if !page_token.is_empty() {
399 query_args.push(("pageToken".to_string(), page_token.to_string()));
400 }
401 if restrict_to_my_drive {
402 query_args.push((
403 "restrictToMyDrive".to_string(),
404 restrict_to_my_drive.to_string(),
405 ));
406 }
407 if !spaces.is_empty() {
408 query_args.push(("spaces".to_string(), spaces.to_string()));
409 }
410 if supports_all_drives {
411 query_args.push((
412 "supportsAllDrives".to_string(),
413 supports_all_drives.to_string(),
414 ));
415 }
416 if supports_team_drives {
417 query_args.push((
418 "supportsTeamDrives".to_string(),
419 supports_team_drives.to_string(),
420 ));
421 }
422 if !team_drive_id.is_empty() {
423 query_args.push(("teamDriveId".to_string(), team_drive_id.to_string()));
424 }
425 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
426 let url = self.client.url(&format!("/changes/watch?{}", query_), None);
427 self.client
428 .post(
429 &url,
430 crate::Message {
431 body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
432 content_type: Some("application/json".to_string()),
433 },
434 )
435 .await
436 }
437}