mangadex_api/v5/
feed.rs

1//! Feed endpoint handler.
2//!
3//! <https://api.mangadex.org/swagger.html#/Feed>
4
5use uuid::Uuid;
6
7use crate::v5::custom_list::id::feed::get::CustomListMangaFeedBuilder;
8use crate::v5::user::follows::manga::get::FollowedMangaBuilder;
9use crate::HttpClientRef;
10
11/// Feed endpoint handler builder.
12#[derive(Debug)]
13pub struct FeedBuilder {
14    http_client: HttpClientRef,
15}
16
17impl FeedBuilder {
18    #[doc(hidden)]
19    pub(crate) fn new(http_client: HttpClientRef) -> Self {
20        Self { http_client }
21    }
22
23    /// Get the manga feed for the logged-in user.
24    ///
25    /// <https://api.mangadex.org/docs/swagger.html#/Feed/get-user-follows-manga-feed>
26    ///
27    /// # Examples
28    ///
29    /// ```rust
30    /// use mangadex_api::v5::MangaDexClient;
31    /// use mangadex_api_types::{Password, Username};
32    ///
33    /// # async fn run() -> anyhow::Result<()> {
34    /// let client = MangaDexClient::default();
35    ///
36    /// let _login_res = client
37    ///     .oauth()
38    ///     .login()
39    ///     .username(Username::parse("myusername")?)
40    ///     .password(Password::parse("hunter23")?)
41    ///     .send()
42    ///     .await?;
43    ///
44    /// let res = client
45    ///     .feed()
46    ///     .followed_manga()
47    ///     .limit(1_u32)
48    ///     .send()
49    ///     .await?;
50    ///
51    /// println!("results: {:?}", res);
52    /// # Ok(())
53    /// # }
54    /// ```
55    pub fn followed_manga(&self) -> FollowedMangaBuilder {
56        FollowedMangaBuilder::default().http_client(self.http_client.clone())
57    }
58
59    /// Get the manga feed for a given custom list.
60    ///
61    /// <https://api.mangadex.org/docs/swagger.html#/Feed/get-list-id-feed>
62    ///
63    /// Alias to [`MangaDexClient::custom_list().id(uuid::Uuid).feed().get()`](crate::v5::custom_list::id::feed::get::CustomListMangaFeedBuilder).
64    ///
65    /// # Examples
66    ///
67    /// ```rust
68    /// use mangadex_api::v5::MangaDexClient;
69    /// use uuid::Uuid;
70    ///
71    /// # async fn run() -> anyhow::Result<()> {
72    /// let client = MangaDexClient::default();
73    ///
74    /// let res = client
75    ///     .feed()
76    ///     .custom_list_manga(Uuid::new_v4())
77    ///     .limit(1_u32)
78    ///     .send()
79    ///     .await?;
80    ///
81    /// println!("results: {:?}", res);
82    /// # Ok(())
83    /// # }
84    /// ```
85    pub fn custom_list_manga(&self, list_id: Uuid) -> CustomListMangaFeedBuilder {
86        CustomListMangaFeedBuilder::default()
87            .list_id(list_id)
88            .http_client(self.http_client.clone())
89    }
90}