twapi_v2/api/
delete_2_users_id_retweets_source_tweet_id.rs1use crate::{
2 api::{Authentication, TwapiOptions, execute_twitter, make_url},
3 error::Error,
4 headers::Headers,
5};
6use reqwest::RequestBuilder;
7use serde::{Deserialize, Serialize};
8
9const URL: &str = "/2/users/:id/retweets/:source_tweet_id";
10
11#[derive(Debug, Clone, Default)]
12pub struct Api {
13 id: String,
14 source_tweet_id: String,
15 twapi_options: Option<TwapiOptions>,
16}
17
18impl Api {
19 pub fn new(id: &str, source_tweet_id: &str) -> Self {
20 Self {
21 id: id.to_owned(),
22 source_tweet_id: source_tweet_id.to_owned(),
23 ..Default::default()
24 }
25 }
26
27 pub fn twapi_options(mut self, value: TwapiOptions) -> Self {
28 self.twapi_options = Some(value);
29 self
30 }
31
32 pub fn build(&self, authentication: &impl Authentication) -> RequestBuilder {
33 let client = reqwest::Client::new();
34 let url = make_url(
35 &self.twapi_options,
36 &URL.replace(":id", &self.id)
37 .replace(":source_tweet_id", &self.source_tweet_id),
38 );
39 let builder = client.delete(&url);
40 authentication.execute(builder, "DELETE", &url, &[])
41 }
42
43 pub async fn execute(
44 &self,
45 authentication: &impl Authentication,
46 ) -> Result<(Response, Headers), Error> {
47 execute_twitter(|| self.build(authentication), &self.twapi_options).await
48 }
49}
50
51#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq)]
52pub struct Response {
53 #[serde(skip_serializing_if = "Option::is_none")]
54 pub data: Option<Data>,
55 #[serde(flatten)]
56 pub extra: std::collections::HashMap<String, serde_json::Value>,
57}
58
59impl Response {
60 pub fn is_empty_extra(&self) -> bool {
61 let res = self.extra.is_empty()
62 && self
63 .data
64 .as_ref()
65 .map(|it| it.is_empty_extra())
66 .unwrap_or(true);
67 if !res {
68 println!("Response {:?}", self.extra);
69 }
70 res
71 }
72}
73
74#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq)]
75pub struct Data {
76 #[serde(skip_serializing_if = "Option::is_none")]
77 pub retweeted: Option<bool>,
78 #[serde(flatten)]
79 pub extra: std::collections::HashMap<String, serde_json::Value>,
80}
81
82impl Data {
83 pub fn is_empty_extra(&self) -> bool {
84 let res = self.extra.is_empty();
85 if !res {
86 println!("Data {:?}", self.extra);
87 }
88 res
89 }
90}