Skip to main content

farcaster_rs/follows/
following.rs

1use crate::constants::merkle::API_ROOT;
2use crate::types::follows::followers::FollowersRoot;
3use crate::Farcaster;
4use std::error::Error;
5
6impl Farcaster {
7    pub async fn get_following_by_fid(
8        &self,
9        fid: i64,
10        limit: Option<i64>,
11        cursor: Option<&str>,
12    ) -> Result<FollowersRoot, Box<dyn Error>> {
13        let mut url = format!("{}/v2/following?fid={}", API_ROOT, fid);
14
15        if limit.is_some() {
16            url.push_str(format!("&limit={}", limit.unwrap()).as_str());
17        }
18
19        if cursor.is_some() {
20            url.push_str(format!("&cursor={}", cursor.unwrap()).as_str());
21        }
22
23        let following_reqwest = &self.reqwest_get(&url).await?;
24
25        let following: FollowersRoot = serde_json::from_str(&following_reqwest)?;
26
27        Ok(following)
28    }
29
30    pub async fn get_following_by_username(
31        &self,
32        username: &str,
33        limit: Option<i64>,
34        cursor: Option<&str>,
35    ) -> Result<FollowersRoot, Box<dyn Error>> {
36        let fid = &self.get_user_by_username(username).await?;
37
38        let following = &self.get_following_by_fid(fid.fid, limit, cursor).await?;
39
40        Ok(following.clone())
41    }
42
43    pub async fn get_following_by_address(
44        &self,
45        address: &str,
46        limit: Option<i64>,
47        cursor: Option<&str>,
48    ) -> Result<FollowersRoot, Box<dyn Error>> {
49        let fid = &self.get_user_by_address(address).await?;
50
51        let following = &self.get_following_by_fid(fid.fid, limit, cursor).await?;
52
53        Ok(following.clone())
54    }
55}