pushover_rs/
lib.rs

1#[cfg(test)]
2mod tests;
3mod pushover;
4
5use pushover::constants::PUSHOVER_API_ENDPOINT;
6pub use pushover::data::{MessageBuilder, AttachmentMessageBuilder};
7pub use pushover::data::PushoverSound;
8pub use pushover::data::Message;
9pub use pushover::data::AttachmentMessage;
10pub use pushover::data::PushoverResponse;
11
12/// Send a push notification without attachment (non blocking)
13pub async fn send_pushover_request(message: Message) -> Result<PushoverResponse, Box<dyn std::error::Error>> {
14    let client: reqwest::Client = reqwest::Client::new();
15    let response: reqwest::Response = client
16        .post(PUSHOVER_API_ENDPOINT)
17        .json(&message)
18        .send()
19        .await?;
20    
21    return PushoverResponse::try_from_reqwest_response(response).await;
22}
23
24/// Send a push notification with attachment (! blocking)
25pub fn send_pushover_request_with_attachment(message: AttachmentMessage) -> Result<PushoverResponse, Box<dyn std::error::Error>> {
26    let client: reqwest::blocking::Client = reqwest::blocking::Client::new();
27    let form: reqwest::blocking::multipart::Form = message.into_form()?;
28    let response: Result<reqwest::blocking::Response, reqwest::Error> = client
29        .post(PUSHOVER_API_ENDPOINT)
30        .multipart(form)
31        .send();
32    
33    return PushoverResponse::try_from_blocking_reqwest_response(response.unwrap());
34}