tweety_rs/api/
like.rs

1use crate::api::client::TweetyClient;
2use crate::api::error::TweetyError;
3use crate::types::types::ResponseWithHeaders;
4use reqwest::Method;
5
6impl TweetyClient {
7    /// DELETE https://api.x.com/2/tweets/:id/likes/:tweet_id
8    /// (unlike a Post)
9    /// https://developer.x.com/en/docs/x-api/tweets/likes/migrate/manage-likes-standard-to-twitter-api-v2
10    pub async fn unlike_tweet(
11        &self,
12        user_id: u64,
13        tweet_id: u64,
14    ) -> Result<ResponseWithHeaders, TweetyError> {
15        let url = format!(
16            "https://api.x.com/2/tweets/:{}/likes/:{}",
17            user_id, tweet_id
18        );
19
20        self.send_request::<()>(&url, Method::DELETE, None).await
21    }
22    /// Users who have liked a Post
23    /// https://developer.x.com/en/docs/x-api/tweets/likes/api-reference
24    pub async fn get_users_who_liked_a_post(
25        &self,
26        post_id: &str,
27    ) -> Result<ResponseWithHeaders, TweetyError> {
28        let url = format!("https://api.x.com/2/tweets/{}/liking_users", post_id);
29
30        self.send_request::<()>(&url, Method::GET, None).await
31    }
32
33    /// Posts liked by a user
34    /// https://developer.x.com/en/docs/x-api/tweets/likes/api-reference
35    pub async fn get_posts_liked_by_a_user(
36        &self,
37        user_id: &str,
38    ) -> Result<ResponseWithHeaders, TweetyError> {
39        let url = format!("https://api.x.com/2/users/{}/liked_tweets", user_id);
40
41        self.send_request::<()>(&url, Method::GET, None).await
42    }
43    /// MANAGE LIKES
44
45    /// Allows a user ID to like a Post
46    /// https://developer.x.com/en/docs/x-api/tweets/likes/api-reference
47    pub async fn like_a_post(&self, user_id: &str) -> Result<ResponseWithHeaders, TweetyError> {
48        let url = format!("https://api.x.com/2/users/{}/likes", user_id);
49
50        self.send_request::<()>(&url, Method::POST, None).await
51    }
52
53    /// Allows a user ID to unlike a Post
54    /// https://developer.x.com/en/docs/x-api/tweets/likes/api-reference
55    pub async fn unlike_a_post(
56        &self,
57        user_id: &str,
58        tweet_id: &str,
59    ) -> Result<ResponseWithHeaders, TweetyError> {
60        let url = format!("https://api.x.com/2/users/{}/likes/{}", user_id, tweet_id);
61
62        self.send_request::<()>(&url, Method::DELETE, None).await
63    }
64}