Skip to main content

twapi_v2/upload/
post_media_metadata_create.rs

1use crate::{
2    api::{Authentication, TwapiOptions},
3    error::Error,
4    headers::Headers,
5    upload::{execute_no_response, make_url},
6};
7use reqwest::RequestBuilder;
8use serde::Serialize;
9
10const URL: &str = "/1.1/media/metadata/create.json";
11
12#[derive(Serialize, Debug, Clone, Default)]
13pub struct AltText {
14    pub text: String,
15}
16
17#[derive(Serialize, Debug, Clone, Default)]
18pub struct Body {
19    pub media_id: String,
20    pub alt_text: AltText,
21}
22
23#[derive(Debug, Clone, Default)]
24pub struct Api {
25    body: Body,
26    twapi_options: Option<TwapiOptions>,
27}
28
29impl Api {
30    pub fn new(body: Body) -> Self {
31        Self {
32            body,
33            ..Default::default()
34        }
35    }
36
37    pub fn twapi_options(mut self, value: TwapiOptions) -> Self {
38        self.twapi_options = Some(value);
39        self
40    }
41
42    pub fn build(self, authentication: &impl Authentication) -> RequestBuilder {
43        let client = reqwest::Client::new();
44        let url = make_url(&self.twapi_options, Some(URL));
45        let builder = client.post(&url).json(&self.body);
46        authentication.execute(builder, "POST", &url, &[])
47    }
48
49    pub async fn execute(self, authentication: &impl Authentication) -> Result<Headers, Error> {
50        execute_no_response(self.build(authentication)).await
51    }
52}