Skip to main content

farcaster_rs/verifications/
get_verifications.rs

1use crate::constants::merkle::API_ROOT;
2use crate::types::verifications::verifications::VerificationsRoot;
3use crate::Farcaster;
4use std::error::Error;
5
6impl Farcaster {
7    /// Get verifications of a user by their FID
8    pub async fn get_verifications_by_fid(
9        &self,
10        fid: i64,
11    ) -> Result<VerificationsRoot, Box<dyn Error>> {
12        let verifications_reqwest = &self
13            .reqwest_get(format!("{}/v2/verifications?fid={}", API_ROOT, fid).as_str())
14            .await?;
15
16        let verifications: VerificationsRoot = serde_json::from_str(&verifications_reqwest)?;
17
18        Ok(verifications)
19    }
20
21    /// Get verifications of a user by their username
22    pub async fn get_verifications_by_username(
23        &self,
24        username: &str,
25    ) -> Result<VerificationsRoot, Box<dyn Error>> {
26        let fid = &self.get_user_by_username(username).await?;
27
28        let verifications = &self.get_verifications_by_fid(fid.fid).await?;
29
30        Ok(verifications.clone())
31    }
32
33    /// Get verifications of a user by their address
34    pub async fn get_verifications_by_address(
35        &self,
36        address: &str,
37    ) -> Result<VerificationsRoot, Box<dyn Error>> {
38        let fid = &self.get_user_by_address(address).await?;
39
40        let verifications = &self.get_verifications_by_fid(fid.fid).await?;
41
42        Ok(verifications.clone())
43    }
44}