pushover_rs/pushover/data/
attachment_message.rs1use reqwest::blocking::multipart::Form;
2use serde::Serialize;
3
4#[derive(Debug, Clone, Serialize)]
5pub struct AttachmentMessage {
11 pub app_token: String,
14 pub user_key: String,
16 pub message: String,
18 pub attachment: String,
20
21 #[serde(skip_serializing_if = "Option::is_none")]
24 pub title: Option<String>,
25 #[serde(skip_serializing_if = "Option::is_none")]
27 pub url: Option<String>,
28 #[serde(skip_serializing_if = "Option::is_none")]
30 pub url_title: Option<String>,
31 #[serde(skip_serializing_if = "Option::is_none")]
33 pub priority: Option<String>,
34 #[serde(skip_serializing_if = "Option::is_none")]
36 pub sound: Option<String>,
37 #[serde(skip_serializing_if = "Option::is_none")]
39 pub timestamp: Option<String>, #[serde(skip_serializing_if = "Option::is_none")]
42 pub device: Option<String>,
43 #[serde(skip_serializing_if = "Option::is_none")]
46 pub ttl: Option<u32>,
47}
48
49impl AttachmentMessage {
50 pub fn into_form(self) -> Result<Form, std::io::Error> {
51 let mut form = Form::new()
52 .text("token", self.app_token.clone())
53 .text("user", self.user_key.clone())
54 .text("message", self.message.clone())
55 .text("title", self.title.clone().unwrap_or(String::from("")))
56 .text("url", self.url.clone().unwrap_or(String::from("")))
57 .text("url_title", self.url_title.clone().unwrap_or(String::from("")))
58 .text("priority", self.priority.unwrap_or(String::from("")))
59 .text("sound", self.sound.clone().unwrap_or(String::from("")))
60 .text("timestamp", self.timestamp.unwrap_or(String::from("")))
61 .text("device", self.device.clone().unwrap_or(String::from("")));
62 if self.ttl.is_some() {
64 form = form.text("ttl", self.ttl.unwrap_or(999).to_string());
65 }
66 form.file("attachment", self.attachment.clone())
67 }
68}
69
70impl Default for AttachmentMessage {
71 fn default() -> Self {
72 Self {
73 app_token: "".into(),
74 user_key: "".into(),
75 message: "".into(),
76 attachment: "".into(),
77 title: None,
78 url: None,
79 url_title: None,
80 priority: None,
81 sound: None,
82 timestamp: None,
83 device: None,
84 ttl: None,
85 }
86 }
87}