mastodon_api\methods/follow_requests.rs
1use crate::MastodonClient;
2use crate::error::Result;
3use crate::models::{Account, Relationship};
4use crate::paging::PagedRequest;
5
6/// Handler for follow request-related API endpoints.
7pub struct FollowRequestsHandler<'a> {
8 client: &'a MastodonClient,
9}
10
11impl<'a> FollowRequestsHandler<'a> {
12 /// Creates a new `FollowRequestsHandler` for the given client.
13 pub fn new(client: &'a MastodonClient) -> Self {
14 Self { client }
15 }
16
17 /// Fetches pending follow requests.
18 ///
19 /// Returns:
20 /// - `Result<Vec<Account>>`: The pending follow requests.
21 ///
22 /// Corresponds to `GET /api/v1/follow_requests`.
23 pub async fn list(&self) -> Result<Vec<Account>> {
24 let url = format!("{}/api/v1/follow_requests", self.client.base_url());
25 let req = self.client.http_client().get(&url);
26 self.client.send(req).await
27 }
28
29 /// Returns a paged request for fetching pending follow requests.
30 pub fn list_paged(&self) -> PagedRequest<'a, Account> {
31 let url = format!("{}/api/v1/follow_requests", self.client.base_url());
32 PagedRequest::new(self.client, url)
33 }
34
35 /// Accepts a follow request from the given account.
36 ///
37 /// Parameters:
38 /// - `id`: The ID of the account whose follow request should be accepted.
39 ///
40 /// Returns:
41 /// - `Result<Relationship>`: The relationship with the accepted account.
42 ///
43 /// Corresponds to `POST /api/v1/follow_requests/:id/authorize`.
44 pub async fn authorize(&self, id: &str) -> Result<Relationship> {
45 let url = format!(
46 "{}/api/v1/follow_requests/{}/authorize",
47 self.client.base_url(),
48 id
49 );
50 let req = self.client.http_client().post(&url);
51 self.client.send(req).await
52 }
53
54 /// Rejects a follow request from the given account.
55 ///
56 /// Parameters:
57 /// - `id`: The ID of the account whose follow request should be rejected.
58 ///
59 /// Returns:
60 /// - `Result<Relationship>`: The relationship with the rejected account.
61 ///
62 /// Corresponds to `POST /api/v1/follow_requests/:id/reject`.
63 pub async fn reject(&self, id: &str) -> Result<Relationship> {
64 let url = format!(
65 "{}/api/v1/follow_requests/{}/reject",
66 self.client.base_url(),
67 id
68 );
69 let req = self.client.http_client().post(&url);
70 self.client.send(req).await
71 }
72}