mastodon_api\methods/
reports.rs

1use crate::MastodonClient;
2use crate::error::Result;
3use crate::models::report::Report;
4
5/// Handler for report-related API endpoints.
6pub struct ReportsHandler<'a> {
7    client: &'a MastodonClient,
8}
9
10impl<'a> ReportsHandler<'a> {
11    /// Creates a new `ReportsHandler` for the given client.
12    pub fn new(client: &'a MastodonClient) -> Self {
13        Self { client }
14    }
15
16    /// Fetches all reports made by the authenticated user.
17    ///
18    /// Returns:
19    /// - `Result<Vec<Report>>`: The reports.
20    ///
21    /// Corresponds to `GET /api/v1/reports`.
22    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    /// Creates a new report.
29    ///
30    /// Parameters:
31    /// - `account_id`: The ID of the account being reported.
32    /// - `status_ids`: IDs of statuses to include in the report.
33    /// - `comment`: A comment to include with the report.
34    /// - `forward`: Whether to forward the report to the remote instance.
35    /// - `category`: The category of the report.
36    /// - `rule_ids`: IDs of rules that were violated.
37    ///
38    /// Returns:
39    /// - `Result<Report>`: The created report.
40    ///
41    /// Corresponds to `POST /api/v1/reports`.
42    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}