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