Crate firebae_cm

Source
Expand description

This crate is a Rust wrapper around the Firebase Cloud Messaging V1 protocol. This allows you to create cloud messages in pure Rust code and send them via push messages to other devices.

It is highly recommended to read the Firebase documentation. In order for this to work, you need a Google Cloud Platform account and Firebase to be setup.

§Usage

This crate can be found on crates.io, so you can use it by adding firebae-cm to your project’s Cargo.toml.

§Example

use firebae_cm::{
    Client,
    Error,
    Message,
    MessageBody,
    Receiver,
};

#[tokio::main]
async fn main() {
    let token = "your_jwt_token";

    // Define the receiver mode (Token, Topic or Condition).
    let receivers = Receiver::topic("subscribers");

    // Create an empty message to your receiver(s).
    let body = MessageBody::new(receivers);

    // Finalize the message with the correct url and authentication.
    let message = Message::new("project_id", token, body);

    // Create a client and send the data.
    let client = Client::new();
    let response: Result<String, Error> = client.send(message).await;
    println!("{:?}", response);
}

§Features

  • oauth - Enables automatic OAuth authentication. You will still need Firebase to be setup correctly and the path to a valid credentials.json file in the GOOGLE_APPLICATION_CREDENTIALS environment variable. Then, creating a message can be done using Message::with_oauth("project_id", body).await?.

Structs§

AndroidConfig
Represents all settings for an Android message. See https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#AndroidConfig for a complete list.
AndroidFcmOptions
Additional Firebase options for Android. Contains only the analytics_label. See https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#androidfcmoptions.
AndroidNotification
Represents the settings for a notification in Android. All settings are optional, and all settings (setter functions) follow the scheme below. See https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#androidnotification.
ApnsConfig
Represents all settings for Apple notifications. See https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#apnsconfig.
ApnsFcmOptions
Additional Firebase options for Apple. See https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#apnsfcmoptions.
Client
A reqwest client wrapper to send Firebase messages.
Color
Represents a color as described in the documentation.
FcmError
A Firebase Cloud Message Error. For example, an invalid JWT token would return the following error:
FcmOptions
Additional platform independent Firebase options. Contains only the analytics_label. See https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#fcmoptions.
FirebaseMap
Represents a String: String map that can be used in some Firebase objects for fields such as data, payload and headers. You can use the crate::AsFirebaseMap derive implementation for ease.
LightSettings
Represents the notification light settings of the notification. See https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#lightsettings. Durations are in seconds.
Message
A representation of a complete message that can be sent. It requires your project_id and an authentication JWT token (see https://cloud.google.com/docs/authentication/). For automatic handling of the JWT authentication, see the oauth feature and the Message::with_oauth function.
MessageBody
A message body as described in https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#resource:-message.
Notification
Represents a basic template for notifications, which is equal across all platforms. See https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#notification. Use the Notification::new function, or initialize the struct yourself:
WebpushConfig
Represents all settings for web. See https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#webpushconfig.
WebpushFcmOptions
Additional Firebase options for web. See https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#webpushfcmoptions.

Enums§

AndroidMessagePriority
Represents the Android message priority. See https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#androidmessagepriority.
Error
All possible errors that can occur in this crate.
FcmResponse
Represents a response by Firebase, whether it is successful or an error.
NotificationPriority
Represents the priority of the notification. See https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#notificationpriority.
Receiver
Represents a receiver of your message. Can be a Token (for a single device), a Topic (for all devices that have subscribed to that topic), or a Condition (for all devices that meet the condition). See the fields in the documentation.
Visibility
Represents the visibility of the notification. See https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#visibility

Traits§

FirebaseMapValue
Trait to convert a value into a String.
IntoFirebaseMap
Trait to convert a struct into a FirebaseMap.

Derive Macros§

AsFirebaseMap