fcm/lib.rs
1#![doc(html_root_url = "https://panicbit.github.io/fcm-rust/fcm/")]
2//! fcm
3//! ===
4//!
5//! A client for asynchronous sending of Firebase Cloud Messages, or Push Notifications.
6//!
7//! # Examples:
8//!
9//! To send out a FCM Message with some custom data:
10//!
11//! ```no_run
12//! # use std::collections::HashMap;
13//! # #[tokio::main]
14//! # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
15//! let client = fcm::Client::new();
16//!
17//! let mut map = HashMap::new();
18//! map.insert("message", "Howdy!");
19//!
20//! let mut builder = fcm::MessageBuilder::new("<FCM API Key>", "<registration id>");
21//! builder.data(&map);
22//!
23//! let response = client.send(builder.finalize()).await?;
24//! println!("Sent: {:?}", response);
25//! # Ok(())
26//! # }
27//! ```
28//!
29//! To send a message using FCM Notifications, we first build the notification:
30//!
31//! ```rust
32//! # fn main() {
33//! let mut builder = fcm::NotificationBuilder::new();
34//! builder.title("Hey!");
35//! builder.body("Do you want to catch up later?");
36//! let notification = builder.finalize();
37//! # }
38//! ```
39//!
40//! And then set it in the message, before sending it:
41//!
42//! ```no_run
43//! # #[tokio::main]
44//! # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
45//! let client = fcm::Client::new();
46//!
47//! let mut notification_builder = fcm::NotificationBuilder::new();
48//! notification_builder.title("Hey!");
49//! notification_builder.body("Do you want to catch up later?");
50//!
51//! let notification = notification_builder.finalize();
52//! let mut message_builder = fcm::MessageBuilder::new("<FCM API Key>", "<registration id>");
53//! message_builder.notification(notification);
54//!
55//! let response = client.send(message_builder.finalize()).await?;
56//! println!("Sent: {:?}", response);
57//! # Ok(())
58//! # }
59//! ```
60
61mod message;
62pub use crate::message::*;
63mod notification;
64pub use crate::notification::*;
65mod client;
66pub use crate::client::*;
67
68pub use crate::client::response::FcmError as Error;