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
#[cfg(test)]
mod tests;
mod pushover;
use pushover::constants::PUSHOVER_API_ENDPOINT;
pub use pushover::data::{MessageBuilder, AttachmentMessageBuilder};
pub use pushover::data::PushoverSound;
pub use pushover::data::Message;
pub use pushover::data::AttachmentMessage;
pub use pushover::data::PushoverResponse;
pub async fn send_pushover_request(message: Message) -> Result<PushoverResponse, Box<dyn std::error::Error>> {
let client: reqwest::Client = reqwest::Client::new();
let response: reqwest::Response = client
.post(PUSHOVER_API_ENDPOINT)
.json(&message)
.send()
.await?;
return PushoverResponse::try_from_reqwest_response(response).await;
}
pub fn send_pushover_request_with_attachment(message: AttachmentMessage) -> Result<PushoverResponse, Box<dyn std::error::Error>> {
let client: reqwest::blocking::Client = reqwest::blocking::Client::new();
let form: reqwest::blocking::multipart::Form = message.into_form()?;
let response: Result<reqwest::blocking::Response, reqwest::Error> = client
.post(PUSHOVER_API_ENDPOINT)
.multipart(form)
.send();
return PushoverResponse::try_from_blocking_reqwest_response(response.unwrap());
}