sfr_slack_api/builder/
files_upload.rs1use sfr_types as st;
4
5use crate::api::files_upload::FilesUpload;
6
7#[derive(Debug, Default)]
9pub struct FilesUploadBuilder {
10 channels: Vec<String>,
12
13 content: Option<String>,
15
16 file: Option<String>,
18
19 file_in_memory: Option<Vec<u8>>,
21
22 filename: Option<String>,
24
25 filetype: Option<String>,
27
28 initial_comment: Option<String>,
30
31 thread_ts: Option<String>,
33
34 title: Option<String>,
36}
37
38impl FilesUploadBuilder {
39 pub fn new() -> Self {
41 Self::default()
42 }
43
44 pub fn build(self) -> Result<FilesUpload, st::Error> {
46 let content = match (self.content, self.file, self.file_in_memory, &self.filename) {
47 (Some(content), _, _, _) => st::FilesUploadRequestContent::Content(content),
48 (None, Some(path), _, Some(filename)) => {
49 st::FilesUploadRequestContent::File(path, filename.clone())
50 }
51 (None, None, Some(bytes), Some(filename)) => {
52 st::FilesUploadRequestContent::FileInMemory(bytes, filename.clone())
53 }
54 _ => {
55 return Err(st::Error::required_value_is_missing(&[
56 "content",
57 "file/filename",
58 ]))
59 }
60 };
61
62 let result = st::FilesUploadRequest {
63 channels: self.channels,
64 content,
65 filename: self.filename,
66 filetype: self.filetype,
67 initial_comment: self.initial_comment,
68 thread_ts: self.thread_ts,
69 title: self.title,
70 };
71
72 Ok(result.into())
73 }
74
75 pub fn channels(mut self, channels: Vec<String>) -> Self {
77 self.channels = channels;
78 self
79 }
80
81 pub fn content(mut self, content: String) -> Self {
83 self.content = Some(content);
84 self.file = None;
85 self
86 }
87
88 pub fn file(mut self, file: String) -> Self {
90 self.file = Some(file);
91 self.content = None;
92 self
93 }
94
95 pub fn filename(mut self, filename: String) -> Self {
97 self.filename = Some(filename);
98 self
99 }
100
101 pub fn filetype(mut self, filetype: String) -> Self {
103 self.filetype = Some(filetype);
104 self
105 }
106
107 pub fn initial_comment(mut self, initial_comment: String) -> Self {
109 self.initial_comment = Some(initial_comment);
110 self
111 }
112
113 pub fn thread_ts(mut self, thread_ts: String) -> Self {
115 self.thread_ts = Some(thread_ts);
116 self
117 }
118
119 pub fn title(mut self, title: String) -> Self {
121 self.title = Some(title);
122 self
123 }
124}