mastodon_api\methods/
reports.rs1use crate::MastodonClient;
2use crate::error::Result;
3use crate::models::report::Report;
4
5pub struct ReportsHandler<'a> {
7 client: &'a MastodonClient,
8}
9
10impl<'a> ReportsHandler<'a> {
11 pub fn new(client: &'a MastodonClient) -> Self {
13 Self { client }
14 }
15
16 pub async fn list(&self) -> Result<Vec<Report>> {
23 let url = format!("{}/api/v1/reports", self.client.base_url());
24 let req = self.client.http_client().get(&url);
25 self.client.send(req).await
26 }
27
28 pub async fn create(
43 &self,
44 account_id: &str,
45 status_ids: Option<&[String]>,
46 comment: Option<&str>,
47 forward: Option<bool>,
48 category: Option<&str>,
49 rule_ids: Option<&[u32]>,
50 ) -> Result<Report> {
51 let url = format!("{}/api/v1/reports", self.client.base_url());
52 let mut req = self.client.http_client().post(&url);
53
54 let mut form = vec![("account_id", account_id.to_string())];
55 if let Some(ids) = status_ids {
56 for id in ids {
57 form.push(("status_ids[]", id.clone()));
58 }
59 }
60 if let Some(c) = comment {
61 form.push(("comment", c.to_string()));
62 }
63 if let Some(f) = forward {
64 form.push(("forward", f.to_string()));
65 }
66 if let Some(cat) = category {
67 form.push(("category", cat.to_string()));
68 }
69 if let Some(r_ids) = rule_ids {
70 for id in r_ids {
71 form.push(("rule_ids[]", id.to_string()));
72 }
73 }
74
75 req = req.form(&form);
76 self.client.send(req).await
77 }
78}