Skip to main content

farcaster_rs/reactions/
get_likes.rs

1use crate::constants::merkle::API_ROOT;
2use crate::types::reactions::liked_casts::ManyLikedCastsRoot;
3use crate::Farcaster;
4use std::error::Error;
5
6impl Farcaster {
7    /// Get likes by the cast hash
8    ///
9    /// # Params
10    /// cast_hash: &str
11    /// limit: Option<i32> - Optional # of likes to get (max 100)
12    /// cursor: Option<&str> - Optional cursor for pagination
13    ///
14    /// # Example
15    /// ```no_run
16    /// farcaster.get_likes_by_cast_hash("cast hash", None, None).await?;
17    /// ```
18    pub async fn get_likes_by_cast_hash(
19        &self,
20        cast_hash: &str,
21        limit: Option<i32>,
22        cursor: Option<&str>,
23    ) -> Result<ManyLikedCastsRoot, Box<dyn Error>> {
24        let mut url = format!("{}/v2/cast-likes?castHash={}", API_ROOT, cast_hash);
25
26        if limit.is_some() {
27            url.push_str(format!("&limit={}", limit.unwrap()).as_str())
28        }
29
30        if cursor.is_some() {
31            url.push_str(format!("&cursor={}", cursor.unwrap()).as_str())
32        }
33
34        let likes_reqwest = &self.reqwest_get(&url).await?;
35
36        let likes: ManyLikedCastsRoot = serde_json::from_str(&likes_reqwest)?;
37
38        Ok(likes)
39    }
40}