rust_v4v/boostagram/
builder.rs

1use crate::Error;
2
3use super::{Action, Boostagram};
4
5pub struct BoostagramBuilder {
6    boostagram: Boostagram,
7}
8
9impl BoostagramBuilder {
10    pub fn build(self) -> Result<Boostagram, Error> {
11        let boost = self.boostagram;
12
13        if boost.podcast.is_none()
14            && boost.feed_id.is_none()
15            && boost.url.is_none()
16            && boost.guid.is_none()
17        {
18            return Err(Error::BuildingError(
19                "either podcast, feed_id, url or guid must be set according to spec".to_string(),
20            ));
21        }
22
23        Ok(boost)
24    }
25
26    pub fn new() -> BoostagramBuilder {
27        BoostagramBuilder {
28            boostagram: Boostagram {
29                podcast: None,
30                feed_id: None,
31                url: None,
32                guid: None,
33                episode: None,
34                item_id: None,
35                episode_guid: None,
36                time: None,
37                ts: None,
38                action: None,
39                app_name: None,
40                app_version: None,
41                boost_link: None,
42                message: None,
43                name: None,
44                sender_name: None,
45                sender_id: None,
46                signature: None,
47                speed: None,
48                uuid: None,
49                value_msat_total: None,
50                reply_address: None,
51                reply_custom_key: None,
52                reply_custom_value: None,
53            },
54        }
55    }
56
57    pub fn podcast(mut self, podcast: String) -> Self {
58        self.boostagram.podcast = Some(podcast);
59        self
60    }
61
62    pub fn podcast_opt(mut self, podcast: Option<String>) -> Self {
63        self.boostagram.podcast = podcast;
64        self
65    }
66
67    pub fn feed_id(mut self, feed_id: usize) -> Self {
68        self.boostagram.feed_id = Some(feed_id);
69        self
70    }
71
72    pub fn feed_id_opt(mut self, feed_id: Option<usize>) -> Self {
73        self.boostagram.feed_id = feed_id;
74        self
75    }
76
77    pub fn url(mut self, url: String) -> Self {
78        self.boostagram.url = Some(url);
79        self
80    }
81
82    pub fn url_opt(mut self, url: Option<String>) -> Self {
83        self.boostagram.url = url;
84        self
85    }
86
87    pub fn guid(mut self, guid: String) -> Self {
88        self.boostagram.guid = Some(guid);
89        self
90    }
91
92    pub fn guid_opt(mut self, guid: Option<String>) -> Self {
93        self.boostagram.guid = guid;
94        self
95    }
96
97    pub fn episode(mut self, episode: String) -> Self {
98        self.boostagram.episode = Some(episode);
99        self
100    }
101
102    pub fn episode_opt(mut self, episode: Option<String>) -> Self {
103        self.boostagram.episode = episode;
104        self
105    }
106
107    pub fn item_id(mut self, item_id: usize) -> Self {
108        self.boostagram.item_id = Some(item_id);
109        self
110    }
111
112    pub fn item_id_opt(mut self, item_id: Option<usize>) -> Self {
113        self.boostagram.item_id = item_id;
114        self
115    }
116
117    pub fn message(mut self, message: String) -> Self {
118        self.boostagram.message = Some(message);
119        self
120    }
121
122    pub fn message_opt(mut self, message: Option<String>) -> Self {
123        self.boostagram.message = message;
124        self
125    }
126
127    pub fn name(mut self, name: String) -> Self {
128        self.boostagram.name = Some(name);
129        self
130    }
131
132    pub fn name_opt(mut self, name: Option<String>) -> Self {
133        self.boostagram.name = name;
134        self
135    }
136
137    pub fn reply_address(mut self, reply_address: String) -> Self {
138        self.boostagram.reply_address = Some(reply_address);
139        self
140    }
141
142    pub fn reply_address_opt(mut self, reply_address: Option<String>) -> Self {
143        self.boostagram.reply_address = reply_address;
144        self
145    }
146
147    pub fn reply_custom_key(mut self, reply_custom_key: usize) -> Self {
148        self.boostagram.reply_custom_key = Some(reply_custom_key);
149        self
150    }
151
152    pub fn reply_custom_key_opt(mut self, reply_custom_key: Option<usize>) -> Self {
153        self.boostagram.reply_custom_key = reply_custom_key;
154        self
155    }
156
157    pub fn reply_custom_value(mut self, reply_custom_value: String) -> Self {
158        self.boostagram.reply_custom_value = Some(reply_custom_value);
159        self
160    }
161
162    pub fn reply_custom_value_opt(mut self, reply_custom_value: Option<String>) -> Self {
163        self.boostagram.reply_custom_value = reply_custom_value;
164        self
165    }
166
167    pub fn sender_name(mut self, sender_name: String) -> Self {
168        self.boostagram.sender_name = Some(sender_name);
169        self
170    }
171
172    pub fn sender_name_opt(mut self, sender_name: Option<String>) -> Self {
173        self.boostagram.sender_name = sender_name;
174        self
175    }
176
177    pub fn sender_id(mut self, sender_id: String) -> Self {
178        self.boostagram.sender_id = Some(sender_id);
179        self
180    }
181
182    pub fn sender_id_opt(mut self, sender_id: Option<String>) -> Self {
183        self.boostagram.sender_id = sender_id;
184        self
185    }
186
187    pub fn signature(mut self, signature: String) -> Self {
188        self.boostagram.signature = Some(signature);
189        self
190    }
191
192    pub fn signature_opt(mut self, signature: Option<String>) -> Self {
193        self.boostagram.signature = signature;
194        self
195    }
196
197    pub fn speed(mut self, speed: String) -> Self {
198        self.boostagram.speed = Some(speed);
199        self
200    }
201
202    pub fn speed_opt(mut self, speed: Option<String>) -> Self {
203        self.boostagram.speed = speed;
204        self
205    }
206
207    pub fn uuid(mut self, uuid: String) -> Self {
208        self.boostagram.uuid = Some(uuid);
209        self
210    }
211
212    pub fn uuid_opt(mut self, uuid: Option<String>) -> Self {
213        self.boostagram.uuid = uuid;
214        self
215    }
216
217    pub fn value_msat_total(mut self, value_msat_total: u64) -> Self {
218        self.boostagram.value_msat_total = Some(value_msat_total);
219        self
220    }
221
222    pub fn value_msat_total_opt(mut self, value_msat_total: Option<u64>) -> Self {
223        self.boostagram.value_msat_total = value_msat_total;
224        self
225    }
226
227    pub fn episode_guid(mut self, episode_guid: String) -> Self {
228        self.boostagram.episode_guid = Some(episode_guid);
229        self
230    }
231
232    pub fn episode_guid_opt(mut self, episode_guid: Option<String>) -> Self {
233        self.boostagram.episode_guid = episode_guid;
234        self
235    }
236
237    pub fn time(mut self, time: String) -> Self {
238        self.boostagram.time = Some(time);
239        self
240    }
241
242    pub fn time_opt(mut self, time: Option<String>) -> Self {
243        self.boostagram.time = time;
244        self
245    }
246
247    pub fn ts(mut self, ts: usize) -> Self {
248        self.boostagram.ts = Some(ts);
249        self
250    }
251
252    pub fn ts_opt(mut self, ts: Option<usize>) -> Self {
253        self.boostagram.ts = ts;
254        self
255    }
256
257    pub fn action(mut self, action: Action) -> Self {
258        self.boostagram.action = Some(action);
259        self
260    }
261
262    pub fn action_opt(mut self, action: Option<Action>) -> Self {
263        self.boostagram.action = action;
264        self
265    }
266
267    pub fn app_name(mut self, app_name: String) -> Self {
268        self.boostagram.app_name = Some(app_name);
269        self
270    }
271
272    pub fn app_name_opt(mut self, app_name: Option<String>) -> Self {
273        self.boostagram.app_name = app_name;
274        self
275    }
276
277    pub fn app_version(mut self, app_version: String) -> Self {
278        self.boostagram.app_version = Some(app_version);
279        self
280    }
281
282    pub fn app_version_opt(mut self, app_version: Option<String>) -> Self {
283        self.boostagram.app_version = app_version;
284        self
285    }
286
287    pub fn boost_link(mut self, boost_link: String) -> Self {
288        self.boostagram.boost_link = Some(boost_link);
289        self
290    }
291
292    pub fn boost_link_opt(mut self, boost_link: Option<String>) -> Self {
293        self.boostagram.boost_link = boost_link;
294        self
295    }
296}
297
298impl Default for BoostagramBuilder {
299    fn default() -> Self {
300        Self::new()
301    }
302}