farcaster_rs/casts/
get_casts.rs1use crate::constants::merkle::API_ROOT;
2use crate::types::casts::casts::CastRoot;
3use crate::types::user::user::UserInfo;
4use crate::Farcaster;
5use std::error::Error;
6
7impl Farcaster {
8 pub async fn get_casts_by_fid(
20 &self,
21 fid: i64,
22 limit: Option<i32>,
23 cursor: Option<&str>,
24 ) -> Result<CastRoot, Box<dyn Error>> {
25 let mut url = format!("{}/v2/casts?fid={}", API_ROOT, fid);
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 println!("{}", url);
35
36 let casts_reqwest = &self.reqwest_get(url.as_str()).await?;
37
38 let casts: CastRoot = serde_json::from_str(casts_reqwest)?;
39
40 Ok(casts)
41 }
42
43 pub async fn get_casts_by_username(
55 &self,
56 username: &str,
57 limit: Option<i32>,
58 cursor: Option<&str>,
59 ) -> Result<CastRoot, Box<dyn Error>> {
60 let fid = &self.get_user_by_username(username).await?;
61
62 let casts = &self.get_casts_by_fid(fid.fid, limit, cursor).await?;
63
64 Ok(casts.clone())
65 }
66
67 pub async fn get_casts_by_address(
79 &self,
80 address: &str,
81 limit: Option<i32>,
82 cursor: Option<&str>,
83 ) -> Result<CastRoot, Box<dyn Error>> {
84 let address: &UserInfo = &self.get_user_by_address(address).await?;
85
86 let casts = &self.get_casts_by_fid(address.fid, limit, cursor).await?;
87
88 Ok(casts.clone())
89 }
90}