Skip to main content

farcaster_rs/casts/
delete_cast.rs

1use crate::constants::merkle::API_ROOT;
2use crate::types::casts::deleted_cast::DeletedCastRoot;
3use crate::Farcaster;
4use serde_json::{json, Value};
5use std::error::Error;
6
7impl Farcaster {
8    /// Delete a cast via its hash
9    ///
10    /// ## Params
11    /// cast_hash: &str
12    ///
13    /// ## Example
14    /// ```no_run
15    /// let casts = farcaster.delete_cast_by_cast_hash("cast_hash").await?;
16    /// ```
17    pub async fn delete_cast_by_cast_hash(
18        &self,
19        cast_hash: &str,
20    ) -> Result<DeletedCastRoot, Box<dyn Error>> {
21        let payload: Value = json!({ "castHash": cast_hash });
22
23        let delete_reqwest = reqwest::Client::new()
24            .delete(format!("{}/v2/casts", API_ROOT))
25            .header("Content-Type", "application/json")
26            .header(
27                "Authorization",
28                &self.account.session_token.as_ref().unwrap().secret,
29            )
30            .json(&payload)
31            .send()
32            .await?
33            .text()
34            .await?;
35
36        let deleted_cast: DeletedCastRoot = serde_json::from_str(&delete_reqwest)?;
37
38        Ok(deleted_cast)
39    }
40}