mastodon_api\methods/
timelines.rs

1use crate::MastodonClient;
2use crate::error::Result;
3use crate::models::Status;
4
5/// Handler for timeline-related API endpoints.
6pub struct TimelinesHandler<'a> {
7    client: &'a MastodonClient,
8}
9
10impl<'a> TimelinesHandler<'a> {
11    pub fn new(client: &'a MastodonClient) -> Self {
12        Self { client }
13    }
14
15    /// Fetches the public timeline.
16    ///
17    /// Corresponds to `GET /api/v1/timelines/public`.
18    pub async fn public(&self) -> Result<Vec<Status>> {
19        let url = format!("{}/api/v1/timelines/public", self.client.base_url());
20        let req = self.client.http_client().get(&url);
21        self.client.send(req).await
22    }
23
24    /// Returns a paged request for the public timeline.
25    ///
26    /// This allows for iterating through the timeline page-by-page.
27    pub async fn public_paged(&self) -> Result<crate::paging::PagedRequest<'_, Status>> {
28        let url = format!("{}/api/v1/timelines/public", self.client.base_url());
29        Ok(crate::paging::PagedRequest::new(self.client, url))
30    }
31
32    /// Fetches the home timeline for the authenticated user.
33    ///
34    /// Corresponds to `GET /api/v1/timelines/home`.
35    pub async fn home(&self) -> Result<Vec<Status>> {
36        let url = format!("{}/api/v1/timelines/home", self.client.base_url());
37        let req = self.client.http_client().get(&url);
38        self.client.send(req).await
39    }
40}