Add this to Cargo.toml
:
rust
[dependencies]
fcm = "0.2"
tokio-core = "0.1"
futures = "0.1"
then add this to your crate root:
rust
extern crate fcm;
extern crate tokio;
extern crate futures;
Here is an example to send out a FCM Message with some custom data:
```rust use std::collections::HashMap; use tokio_core::reactor::Core; use fcm::{Client, MessageBuilder};
let mut core = 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 = MessageBuilder::new("
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:
```rust use std::collections::HashMap; use tokio_core::reactor::Core; use fcm::{Client, NotificationBuilder};
let mut core = Core::new().unwrap(); let handle = core.handle(); let client = Client::new(&handle).unwrap();
let mut builder = NotificationBuilder::new("Hey!"); builder.body("Do you want to catch up later?"); let notification = builder.finalize(); ```
And then set it in the message, before sending it:
```rust
let mut builder = MessageBuilder::new("
let work = client.send(builder.finalize()); let result = core.run(work); ```