1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
use std::path::Path;
use chrono::prelude::*;
use reqwest::multipart::Form;
use crate::Result;
#[derive(Debug, Clone, Deserialize)]
pub struct Account {
pub acct: String,
pub avatar: String,
pub avatar_static: String,
pub created_at: DateTime<Utc>,
pub display_name: String,
pub followers_count: u64,
pub following_count: u64,
pub header: String,
pub header_static: String,
pub id: String,
pub locked: bool,
pub note: String,
pub statuses_count: u64,
pub url: String,
pub username: String,
pub source: Option<Source>,
pub moved: Option<Box<Account>>,
}
#[derive(Debug, Clone, Deserialize)]
pub struct Source {
privacy: crate::status_builder::Visibility,
sensitive: bool,
note: String,
}
pub struct CredientialsBuilder<'a> {
display_name: Option<&'a str>,
note: Option<&'a str>,
avatar: Option<&'a Path>,
header: Option<&'a Path>,
}
impl<'a> CredientialsBuilder<'a> {
pub fn into_form(self) -> Result<Form> {
let mut form = Form::new();
macro_rules! add_to_form {
($key:ident : Text; $($rest:tt)*) => {{
if let Some(val) = self.$key {
form = form.text(stringify!($key), val.to_owned());
}
add_to_form!{$($rest)*}
}};
($key:ident : File; $($rest:tt)*) => {{
if let Some(val) = self.$key {
form = form.file(stringify!($key), val)?;
}
add_to_form!{$($rest)*}
}};
() => {}
}
add_to_form! {
display_name: Text;
note: Text;
avatar: File;
header: File;
}
Ok(form)
}
}