twitter_v2/requests/
list.rs1use std::marker::PhantomData;
2
3use crate::api::TwitterApi;
4use crate::api_result::ApiResult;
5use crate::authorization::Authorization;
6use reqwest::Method;
7use serde::{de::DeserializeOwned, Deserialize, Serialize};
8use url::Url;
9
10#[derive(Clone, Default, Debug, Serialize, Deserialize)]
11struct DraftList {
12 #[serde(skip_serializing_if = "Option::is_none")]
13 pub name: Option<String>,
14 #[serde(skip_serializing_if = "Option::is_none")]
15 pub description: Option<String>,
16 #[serde(skip_serializing_if = "Option::is_none")]
17 pub private: Option<bool>,
18}
19
20#[derive(Debug)]
21pub struct ListBuilder<A, T> {
22 client: TwitterApi<A>,
23 url: Url,
24 method: Method,
25 list: DraftList,
26 return_ty: PhantomData<T>,
27}
28
29impl<A, T> ListBuilder<A, T>
30where
31 A: Authorization,
32 T: DeserializeOwned,
33{
34 pub(crate) fn new(client: &TwitterApi<A>, url: Url, method: Method) -> Self {
35 Self {
36 client: client.clone(),
37 url,
38 method,
39 list: Default::default(),
40 return_ty: Default::default(),
41 }
42 }
43 pub fn name(&mut self, name: impl ToString) -> &mut Self {
44 self.list.name = Some(name.to_string());
45 self
46 }
47 pub fn description(&mut self, description: impl ToString) -> &mut Self {
48 self.list.description = Some(description.to_string());
49 self
50 }
51 pub fn private(&mut self, private: bool) -> &mut Self {
52 self.list.private = Some(private);
53 self
54 }
55 pub async fn send(&self) -> ApiResult<A, T, ()> {
56 self.client
57 .send(
58 self.client
59 .request(self.method.clone(), self.url.clone())
60 .json(&self.list),
61 )
62 .await
63 }
64}
65
66impl<A, T> Clone for ListBuilder<A, T> {
67 fn clone(&self) -> Self {
68 Self {
69 client: self.client.clone(),
70 url: self.url.clone(),
71 method: self.method.clone(),
72 list: self.list.clone(),
73 return_ty: Default::default(),
74 }
75 }
76}