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
use std::collections::HashMap;
use std::path::PathBuf;
pub struct UploadRequest {
pub(crate) comment: Option<String>,
pub(crate) tags: Vec<String>,
pub(crate) text: Option<String>,
pub(crate) ignore_warnings: bool,
pub(crate) file: PathBuf,
pub(crate) chunk_size: usize,
}
impl UploadRequest {
pub fn from_path(path: PathBuf) -> Self {
Self {
comment: None,
tags: vec![],
text: None,
ignore_warnings: false,
file: path,
chunk_size: 5_000_000,
}
}
pub fn comment(mut self, comment: String) -> Self {
self.comment = Some(comment);
self
}
pub fn tags(mut self, tags: Vec<String>) -> Self {
self.tags.extend(tags);
self
}
pub fn text(mut self, text: String) -> Self {
self.text = Some(text);
self
}
pub fn ignore_warnings(mut self, val: bool) -> Self {
self.ignore_warnings = val;
self
}
pub fn chunk_size(mut self, val: usize) -> Self {
self.chunk_size = val;
self
}
pub(crate) fn params(&self) -> HashMap<&'static str, String> {
let mut params = HashMap::new();
if let Some(comment) = &self.comment {
params.insert("comment", comment.to_string());
}
if !self.tags.is_empty() {
params.insert("tags", self.tags.join("|"));
}
if let Some(text) = &self.text {
params.insert("text", text.to_string());
}
params
}
}