Skip to main content

farcaster_rs/reactions/
get_recasters.rs

1use crate::constants::merkle::API_ROOT;
2use crate::types::reactions::recasters::RecastersRoot;
3use crate::Farcaster;
4use std::error::Error;
5
6impl Farcaster {
7    /// Get recasters by cast hash
8    ///
9    /// # Params
10    /// cast_hash: &str,
11    /// limit: Option<i32> - Optional # of recasters to get (max 100)
12    /// cursor: Option<&str) - Optional cursor for pagination
13    ///
14    /// # Example
15    /// ```no_run
16    /// let recasters = farcaster.get_recasters.by_cast_hash("cast hash", None, None).await?;
17    /// ```
18    pub async fn get_recasters_by_cast_hash(
19        &self,
20        cast_hash: &str,
21        limit: Option<i32>,
22        cursor: Option<&str>,
23    ) -> Result<RecastersRoot, Box<dyn Error>> {
24        let mut url = format!("{}/v2/cast-recasters?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 recasters_reqwest = reqwest::Client::new()
35            .delete(url)
36            .header("Content-Type", "application/json ")
37            .header(
38                "Authorization",
39                &self.account.session_token.as_ref().unwrap().secret,
40            )
41            .send()
42            .await?
43            .text()
44            .await?;
45
46        let recasters: RecastersRoot = serde_json::from_str(&recasters_reqwest)?;
47
48        Ok(recasters)
49    }
50}