Skip to content

Commit

Permalink
docs: update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
adnanjpg committed Jan 31, 2024
1 parent 0dbb30b commit e9d5d9d
Showing 1 changed file with 74 additions and 1 deletion.
75 changes: 74 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 <device_token>`



0 comments on commit e9d5d9d

Please sign in to comment.