Skip to main content

twapi_v2/api/
delete_2_users_id_pinned_lists.rs

1use crate::{
2    api::{Authentication, TwapiOptions, apply_options, 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/pinned_lists/:list_id";
10
11#[derive(Debug, Clone, Default)]
12pub struct Api {
13    id: String,
14    list_id: String,
15    twapi_options: Option<TwapiOptions>,
16}
17
18impl Api {
19    pub fn new(id: &str, list_id: &str) -> Self {
20        Self {
21            id: id.to_owned(),
22            list_id: list_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(":list_id", &self.list_id),
38        );
39        let builder = client.delete(&url);
40        authentication.execute(
41            apply_options(builder, &self.twapi_options),
42            "DELETE",
43            &url,
44            &[],
45        )
46    }
47
48    pub async fn execute(
49        self,
50        authentication: &impl Authentication,
51    ) -> Result<(Response, Headers), Error> {
52        execute_twitter(self.build(authentication)).await
53    }
54}
55
56#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq)]
57pub struct Response {
58    #[serde(skip_serializing_if = "Option::is_none")]
59    pub data: Option<Data>,
60    #[serde(flatten)]
61    pub extra: std::collections::HashMap<String, serde_json::Value>,
62}
63
64impl Response {
65    pub fn is_empty_extra(&self) -> bool {
66        let res = self.extra.is_empty()
67            && self
68                .data
69                .as_ref()
70                .map(|it| it.is_empty_extra())
71                .unwrap_or(true);
72        if !res {
73            println!("Response {:?}", self.extra);
74        }
75        res
76    }
77}
78
79#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq)]
80pub struct Data {
81    #[serde(skip_serializing_if = "Option::is_none")]
82    pub pinned: Option<bool>,
83    #[serde(flatten)]
84    pub extra: std::collections::HashMap<String, serde_json::Value>,
85}
86
87impl Data {
88    pub fn is_empty_extra(&self) -> bool {
89        let res = self.extra.is_empty();
90        if !res {
91            println!("Data {:?}", self.extra);
92        }
93        res
94    }
95}