pushover/
lib.rs

1//! # Pushover API Wrapper
2//!
3//! https://pushover.net/api
4//!
5//! ## Usage
6//! Add the following to `Cargo.toml`:
7//!
8//! ```rust,ignore
9//! [dependencies]
10//! pushover = "0.4.0"
11//! ```
12//!
13//! Synchronous example:
14//!
15//! ```rust,no_run
16//!
17//! use pushover::API;
18//! use pushover::requests::message::SendMessage;
19//!
20//! fn send_message() {
21//!     let api = API::new();
22//!
23//!     let msg = SendMessage::new("token", "user_key", "hello");
24//!
25//!     let response = api.send(&msg);
26//!     println!("{:?}", response.expect("Error sending message"));
27//! }
28//!
29//! ```
30//!
31//! Asynchronous example:
32//!
33//! ```rust,no_run
34//!
35//! use pushover::API;
36//! use pushover::requests::message::SendMessage;
37//!
38//! async fn send_message() {
39//!     let api = API::new();
40//!
41//!     let msg = SendMessage::new("token", "user_key", "hello");
42//!     let response = api.send_async(&msg).await;
43//!
44//!     println!("{:?}", response.expect("Error sending message"));
45//! }
46//! ```
47
48mod client;
49mod deserializers;
50mod error;
51pub mod requests;
52mod types;
53
54pub use self::client::API;
55pub use self::error::{Error, ErrorKind};
56pub use self::types::{OperatingSystem, Priority, Sound, User, UserType};
57
58#[cfg(test)]
59mod test {
60    use crate::client::{API_URL, API_VERSION};
61    use crate::requests::Request;
62    use url::Url;
63
64    pub fn assert_req_url<R>(req: &R, path: &str, iter: Option<&[(&str, &str)]>)
65    where
66        R: Request,
67    {
68        let mut url = Url::parse(&format!("{}/{}", API_URL, API_VERSION)).unwrap();
69        req.build_url(&mut url);
70
71        let expected_url = match iter {
72            Some(x) => {
73                Url::parse_with_params(&format!("{}/{}/{}", API_URL, API_VERSION, path), x).unwrap()
74            }
75            None => Url::parse(&format!("{}/{}/{}", API_URL, API_VERSION, path)).unwrap(),
76        };
77
78        assert_eq!(expected_url, url);
79    }
80}