diff --git a/README.md b/README.md index b74bfbd09..7c361866b 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,70 @@ This fork is a rewrite to use Google's HTTP v1 API. + +# Getting started + +## Installation + +Add the following to your `Cargo.toml` file: + +```toml +[dependencies] +fcm = { git = "https://github.com/rj76/fcm-rust.git" } +``` + +Then, you need to add the credentials described in the [Credentials](#credentials) to a `.env` file at the root of your project. + +## Usage + +For a complete usage example, you may check the [Examples](#examples) section. + +### Import + +```rust +use fcm; +``` + +### Create a client instance + +```rust +let client = fcm::Client::new(); +``` + +### Construct a message + +```rust +let message = fcm::Message { + data: None, + notification: Some(Notification { + title: Some("I'm high".to_string()), + body: Some(format!("it's {}", chrono::Utc::now())), + ..Default::default() + }), + target: Target::Token(device_token), + fcm_options: Some(FcmOptions { + analytics_label: "analytics_label".to_string(), + }), + android: Some(AndroidConfig { + priority: Some(fcm::AndroidMessagePriority::High), + notification: Some(AndroidNotification { + title: Some("I'm Android high".to_string()), + body: Some(format!("Hi Android, it's {}", chrono::Utc::now())), + ..Default::default() + }), + ..Default::default() + }), + apns: Some(ApnsConfig { ..Default::default() }), + webpush: Some(WebpushConfig { ..Default::default() }), +} +``` + +### Send the message + +```rust +let response = client.send(message).await?; +``` + # Credentials This library expects the Google credentials JSON location to be @@ -19,4 +83,13 @@ Please follow the instructions in the [Firebase Documentation](https://firebase. ## Examples -Check out the examples directory for a simple sender. +For a complete usage example, you may check out the [`simple_sender`](examples/simple_sender.rs) example. + +To run the example, first of all clone the [`.env.example`](.env.example) file to `.env` and fill in the required values. + +You can find info about the required credentials in the [Credentials](#credentials) section. + +Then run the example with `cargo run --example simple_sender -- -t ` + + +