mastodon_api\methods/suggestions.rs
1use crate::MastodonClient;
2use crate::error::Result;
3use crate::models::suggestion::Suggestion;
4
5/// Handler for suggestion-related API endpoints.
6pub struct SuggestionsHandler<'a> {
7 client: &'a MastodonClient,
8}
9
10impl<'a> SuggestionsHandler<'a> {
11 /// Creates a new `SuggestionsHandler` for the given client.
12 pub fn new(client: &'a MastodonClient) -> Self {
13 Self { client }
14 }
15
16 /// Fetches accounts suggested for follow.
17 ///
18 /// Parameters:
19 /// - `limit`: Maximum number of results to return.
20 ///
21 /// Returns:
22 /// - `Result<Vec<Suggestion>>`: The account suggestions.
23 ///
24 /// Corresponds to `GET /api/v1/suggestions`.
25 pub async fn list(&self, limit: Option<u32>) -> Result<Vec<Suggestion>> {
26 let url = format!("{}/api/v1/suggestions", self.client.base_url());
27 let mut req = self.client.http_client().get(&url);
28 if let Some(l) = limit {
29 req = req.query(&[("limit", l.to_string())]);
30 }
31 self.client.send(req).await
32 }
33
34 /// Removes an account from suggestions.
35 ///
36 /// Parameters:
37 /// - `account_id`: The ID of the account to remove from suggestions.
38 ///
39 /// Returns:
40 /// - `Result<()>`: Success if the account was removed from suggestions.
41 ///
42 /// Corresponds to `DELETE /api/v1/suggestions/:account_id`.
43 pub async fn remove(&self, account_id: &str) -> Result<()> {
44 let url = format!(
45 "{}/api/v1/suggestions/{}",
46 self.client.base_url(),
47 account_id
48 );
49 let req = self.client.http_client().delete(&url);
50 self.client.send(req).await
51 }
52}