mastodon_api\methods/domain_blocks.rs
1use crate::MastodonClient;
2use crate::error::Result;
3
4/// Handler for domain block-related API endpoints.
5pub struct DomainBlocksHandler<'a> {
6 client: &'a MastodonClient,
7}
8
9impl<'a> DomainBlocksHandler<'a> {
10 /// Creates a new `DomainBlocksHandler` for the given client.
11 pub fn new(client: &'a MastodonClient) -> Self {
12 Self { client }
13 }
14
15 /// Fetches all domains blocked by the authenticated user.
16 ///
17 /// Returns:
18 /// - `Result<Vec<String>>`: The blocked domains.
19 ///
20 /// Corresponds to `GET /api/v1/domain_blocks`.
21 pub async fn list(&self) -> Result<Vec<String>> {
22 let url = format!("{}/api/v1/domain_blocks", self.client.base_url());
23 let req = self.client.http_client().get(&url);
24 self.client.send(req).await
25 }
26
27 /// Blocks a domain for the authenticated user.
28 ///
29 /// Parameters:
30 /// - `domain`: The domain to block.
31 ///
32 /// Returns:
33 /// - `Result<()>`: Success if the domain was blocked.
34 ///
35 /// Corresponds to `POST /api/v1/domain_blocks`.
36 pub async fn block(&self, domain: &str) -> Result<()> {
37 let url = format!("{}/api/v1/domain_blocks", self.client.base_url());
38 let req = self
39 .client
40 .http_client()
41 .post(&url)
42 .form(&[("domain", domain)]);
43 self.client.send(req).await
44 }
45
46 /// Unblocks a domain.
47 ///
48 /// Parameters:
49 /// - `domain`: The domain to unblock.
50 ///
51 /// Returns:
52 /// - `Result<()>`: Success if the domain was unblocked.
53 ///
54 /// Corresponds to `DELETE /api/v1/domain_blocks`.
55 pub async fn unblock(&self, domain: &str) -> Result<()> {
56 let url = format!("{}/api/v1/domain_blocks", self.client.base_url());
57 let req = self
58 .client
59 .http_client()
60 .delete(&url)
61 .form(&[("domain", domain)]);
62 self.client.send(req).await
63 }
64}