google_drive/revisions.rs
1use crate::Client;
2use crate::ClientResult;
3
4pub struct Revisions {
5 pub client: Client,
6}
7
8impl Revisions {
9 #[doc(hidden)]
10 pub fn new(client: Client) -> Self {
11 Revisions { client }
12 }
13
14 /**
15 * This function performs a `GET` to the `/files/{fileId}/revisions` endpoint.
16 *
17 * Lists a file's revisions.
18 *
19 * **Parameters:**
20 *
21 * * `file_id: &str` -- A link to this theme's background image.
22 * * `page_size: i64` -- A map of maximum import sizes by MIME type, in bytes.
23 * * `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.
24 */
25 pub async fn list(
26 &self,
27 file_id: &str,
28 page_size: i64,
29 page_token: &str,
30 ) -> ClientResult<crate::Response<Vec<crate::types::Revision>>> {
31 let mut query_args: Vec<(String, String)> = Default::default();
32 if page_size > 0 {
33 query_args.push(("pageSize".to_string(), page_size.to_string()));
34 }
35 if !page_token.is_empty() {
36 query_args.push(("pageToken".to_string(), page_token.to_string()));
37 }
38 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
39 let url = self.client.url(
40 &format!(
41 "/files/{}/revisions?{}",
42 crate::progenitor_support::encode_path(file_id),
43 query_
44 ),
45 None,
46 );
47 let resp: crate::Response<crate::types::RevisionList> = self
48 .client
49 .get(
50 &url,
51 crate::Message {
52 body: None,
53 content_type: None,
54 },
55 )
56 .await?;
57
58 // Return our response data.
59 Ok(crate::Response::new(
60 resp.status,
61 resp.headers,
62 resp.body.revisions.to_vec(),
63 ))
64 }
65 /**
66 * This function performs a `GET` to the `/files/{fileId}/revisions` endpoint.
67 *
68 * As opposed to `list`, this function returns all the pages of the request at once.
69 *
70 * Lists a file's revisions.
71 */
72 pub async fn list_all(
73 &self,
74 file_id: &str,
75 ) -> ClientResult<crate::Response<Vec<crate::types::Revision>>> {
76 let url = self.client.url(
77 &format!(
78 "/files/{}/revisions",
79 crate::progenitor_support::encode_path(file_id),
80 ),
81 None,
82 );
83 let crate::Response::<crate::types::RevisionList> {
84 mut status,
85 mut headers,
86 mut body,
87 } = self
88 .client
89 .get(
90 &url,
91 crate::Message {
92 body: None,
93 content_type: None,
94 },
95 )
96 .await?;
97
98 let mut revisions = body.revisions;
99 let mut page = body.next_page_token;
100
101 // Paginate if we should.
102 while !page.is_empty() {
103 if !url.contains('?') {
104 crate::Response::<crate::types::RevisionList> {
105 status,
106 headers,
107 body,
108 } = self
109 .client
110 .get(
111 &format!("{}?pageToken={}", url, page),
112 crate::Message {
113 body: None,
114 content_type: None,
115 },
116 )
117 .await?;
118 } else {
119 crate::Response::<crate::types::RevisionList> {
120 status,
121 headers,
122 body,
123 } = self
124 .client
125 .get(
126 &format!("{}&pageToken={}", url, page),
127 crate::Message {
128 body: None,
129 content_type: None,
130 },
131 )
132 .await?;
133 }
134
135 revisions.append(&mut body.revisions);
136
137 if !body.next_page_token.is_empty() && body.next_page_token != page {
138 page = body.next_page_token.to_string();
139 } else {
140 page = "".to_string();
141 }
142 }
143
144 // Return our response data.
145 Ok(crate::Response::new(status, headers, revisions))
146 }
147 /**
148 * This function performs a `GET` to the `/files/{fileId}/revisions/{revisionId}` endpoint.
149 *
150 * Gets a revision's metadata or content by ID.
151 *
152 * **Parameters:**
153 *
154 * * `file_id: &str` -- A link to this theme's background image.
155 * * `revision_id: &str` -- A link to this theme's background image.
156 * * `acknowledge_abuse: bool` -- Whether the user is acknowledging the risk of downloading known malware or other abusive files. This is only applicable when alt=media.
157 */
158 pub async fn get(
159 &self,
160 file_id: &str,
161 revision_id: &str,
162 acknowledge_abuse: bool,
163 ) -> ClientResult<crate::Response<crate::types::Revision>> {
164 let mut query_args: Vec<(String, String)> = Default::default();
165 if acknowledge_abuse {
166 query_args.push((
167 "acknowledgeAbuse".to_string(),
168 acknowledge_abuse.to_string(),
169 ));
170 }
171 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
172 let url = self.client.url(
173 &format!(
174 "/files/{}/revisions/{}?{}",
175 crate::progenitor_support::encode_path(file_id),
176 crate::progenitor_support::encode_path(revision_id),
177 query_
178 ),
179 None,
180 );
181 self.client
182 .get(
183 &url,
184 crate::Message {
185 body: None,
186 content_type: None,
187 },
188 )
189 .await
190 }
191 /**
192 * This function performs a `DELETE` to the `/files/{fileId}/revisions/{revisionId}` endpoint.
193 *
194 * Permanently deletes a file version. You can only delete revisions for files with binary content in Google Drive, like images or videos. Revisions for other files, like Google Docs or Sheets, and the last remaining file version can't be deleted.
195 *
196 * **Parameters:**
197 *
198 * * `file_id: &str` -- A link to this theme's background image.
199 * * `revision_id: &str` -- A link to this theme's background image.
200 */
201 pub async fn delete(
202 &self,
203 file_id: &str,
204 revision_id: &str,
205 ) -> ClientResult<crate::Response<()>> {
206 let url = self.client.url(
207 &format!(
208 "/files/{}/revisions/{}",
209 crate::progenitor_support::encode_path(file_id),
210 crate::progenitor_support::encode_path(revision_id),
211 ),
212 None,
213 );
214 self.client
215 .delete(
216 &url,
217 crate::Message {
218 body: None,
219 content_type: None,
220 },
221 )
222 .await
223 }
224 /**
225 * This function performs a `PATCH` to the `/files/{fileId}/revisions/{revisionId}` endpoint.
226 *
227 * Updates a revision with patch semantics.
228 *
229 * **Parameters:**
230 *
231 * * `file_id: &str` -- A link to this theme's background image.
232 * * `revision_id: &str` -- A link to this theme's background image.
233 */
234 pub async fn update(
235 &self,
236 file_id: &str,
237 revision_id: &str,
238 body: &crate::types::Revision,
239 ) -> ClientResult<crate::Response<crate::types::Revision>> {
240 let url = self.client.url(
241 &format!(
242 "/files/{}/revisions/{}",
243 crate::progenitor_support::encode_path(file_id),
244 crate::progenitor_support::encode_path(revision_id),
245 ),
246 None,
247 );
248 self.client
249 .patch(
250 &url,
251 crate::Message {
252 body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
253 content_type: Some("application/json".to_string()),
254 },
255 )
256 .await
257 }
258}