Crate fcm [−] [src]
fcm
Usage:
Add this to Cargo.toml
:
[dependencies] fcm = "0.2.0"
then add this to your crate root:
extern crate fcm; extern crate futures; extern crate tokio_core;
Examples:
Here is an example to send out a FCM Message with some custom data:
let mut core = tokio_core::reactor::Core::new().unwrap(); let handle = core.handle(); let client = fcm::Client::new(&handle).unwrap(); let mut map = HashMap::new(); map.insert("message", "Howdy!"); let mut builder = fcm::MessageBuilder::new("<FCM API Key>", "<registration id>"); builder.data(map); let work = client.send(builder.finalize()); match core.run(work) { Ok(response) => println!("Sent: {:?}", response), Err(error) => println!("Error: {:?}", error), };
To send a message using FCM Notifications, we first build the notification:
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:
let mut core = tokio_core::reactor::Core::new().unwrap(); let handle = core.handle(); let client = fcm::Client::new(&handle).unwrap(); 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 work = client.send(message_builder.finalize()); let result = core.run(work); match result { Ok(response) => println!("message_id: {:?}", response.message_id), Err(error) => println!("Error: {:?}", error), }
Modules
response |
Structs
Client | |
FcmResponse | |
FutureResponse | |
Message |
Represents a FCM message. Construct the FCM message using various utility methods and finally send it. |
MessageBuilder |
A builder to get a |
MessageResult | |
Notification |
This struct represents a FCM notification. Use the
corresponding |
NotificationBuilder |
A builder to get a |
Enums
Error | |
FcmError | |
Priority |
Traits
Service |
An asynchronous function from |