Skip to main content

farcaster_rs/notifications/
get_notifications.rs

1use crate::constants::merkle::API_ROOT;
2use crate::types::notifications::notifications::NotificationsRoot;
3use crate::Farcaster;
4use std::error::Error;
5
6impl Farcaster {
7    /// Fetch your notifications
8    ///
9    /// # Params
10    /// limit: Option<i64> - How many casts to get (max 100)
11    /// cursor: Option<&str) - For pagination
12    ///
13    /// # Example
14    /// ```no_run
15    /// let notifications = farcaster.get_notifications(None, None).await?;
16    /// ```
17    pub async fn get_notifications(
18        &self,
19        limit: Option<i64>,
20        cursor: Option<&str>,
21    ) -> Result<NotificationsRoot, Box<dyn Error>> {
22        let mut url = format!("{}/v2/mention-and-reply-notifications", API_ROOT);
23
24        if limit.is_some() {
25            url.push_str(format!("&limit={}", limit.unwrap()).as_str())
26        }
27
28        if cursor.is_some() {
29            url.push_str(format!("&cursor={}", cursor.unwrap()).as_str())
30        }
31
32        let notifications_reqwest = &self.reqwest_get(&url).await?;
33
34        let notifications: NotificationsRoot = serde_json::from_str(&notifications_reqwest)?;
35
36        Ok(notifications)
37    }
38}