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 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 Ok(crate::Response::new(
68 resp.status,
69 resp.headers,
70 resp.body.replies.to_vec(),
71 ))
72 }
73 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 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 Ok(crate::Response::new(status, headers, replies))
163 }
164 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 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 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 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}