19 releases

0.9.2 Jul 27, 2022
0.9.1 Mar 26, 2021
0.8.1 Dec 31, 2020
0.7.1 Dec 17, 2019
0.1.1 May 22, 2016

#485 in Web programming

Download history 624/week @ 2023-02-13 674/week @ 2023-02-20 593/week @ 2023-02-27 471/week @ 2023-03-06 511/week @ 2023-03-13 606/week @ 2023-03-20 711/week @ 2023-03-27 618/week @ 2023-04-03 632/week @ 2023-04-10 795/week @ 2023-04-17 672/week @ 2023-04-24 548/week @ 2023-05-01 607/week @ 2023-05-08 489/week @ 2023-05-15 530/week @ 2023-05-22 556/week @ 2023-05-29

2,231 downloads per month
Used in 2 crates

MIT license

42KB
778 lines

fcm

Cargo tests Coveralls [Crates.io Version][crates.io] [Crates.io Downloads][crates.io] [Crates.io License][crates.io]

Matrix chat

Requirements

Needs a Tokio executor version 1.0 or later and Rust compiler version 1.45.0 or later.

Examples

Check out the examples directory for a simple sender.


lib.rs:

fcm

A client for asynchronous sending of Firebase Cloud Messages, or Push Notifications.

Examples:

To send out a FCM Message with some custom data:

# use std::collections::HashMap;
# #[tokio::main]
# async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let client = fcm::Client::new();

let mut map = HashMap::new();
map.insert("message", "Howdy!");

let mut builder = fcm::MessageBuilder::new("<FCM API Key>", "<registration id>");
builder.data(&map);

let response = client.send(builder.finalize()).await?;
println!("Sent: {:?}", response);
# Ok(())
# }

To send a message using FCM Notifications, we first build the notification:

# fn main() {
let mut builder = fcm::NotificationBuilder::new();
builder.title("Hey!");
builder.body("Do you want to catch up later?");
let notification = builder.finalize();
# }

And then set it in the message, before sending it:

# #[tokio::main]
# async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let client = fcm::Client::new();

let mut notification_builder = fcm::NotificationBuilder::new();
notification_builder.title("Hey!");
notification_builder.body("Do you want to catch up later?");

let notification = notification_builder.finalize();
let mut message_builder = fcm::MessageBuilder::new("<FCM API Key>", "<registration id>");
message_builder.notification(notification);

let response = client.send(message_builder.finalize()).await?;
println!("Sent: {:?}", response);
# Ok(())
# }

Dependencies

~5–14MB
~298K SLoC