Struct fcm::Message [] [src]

pub struct Message<'a> {
    // some fields omitted
}

Represents a FCM message. Construct the FCM message using various utility methods and finally send it.

Examples:

use fcm::Message;
 
let message = Message::new("<registration id>").dry_run(true);

Methods

impl<'a> Message<'a>
[src]

fn new(to: &'a str) -> Message

Get a new instance of Message. You need to supply either a registration id, or a topic (/topic/...).

fn registration_ids(self, ids: Vec<&'a str>) -> Message<'a>

Set various registration ids to which the message ought to be sent.

fn collapse_key(self, collapse_key: &'a str) -> Message<'a>

Set this parameter to identify groups of messages that can be collapsed.

fn priority(self, priority: Priority) -> Message<'a>

Set the priority of the message. You can set Normal or High priorities.

Examples:

use fcm::{Message, Priority};
 
let message = Message::new("<registration id>")
    .priority(Priority::High);

fn content_available(self, content_available: bool) -> Message<'a>

To set the content-available field on iOS

fn delay_while_idle(self, delay_while_idle: bool) -> Message<'a>

When set to true, sends the message only when the device is active.

fn time_to_live(self, time_to_live: i32) -> Message<'a>

How long (in seconds) to keep the message on FCM servers in case the device is offline. The maximum and default is 4 weeks.

fn restricted_package_name(self, restricted_package_name: &'a str) -> Message<'a>

Package name of the application where the registration tokens must match.

fn dry_run(self, dry_run: bool) -> Message<'a>

When set to true, allows you to test FCM without actually sending the message.

fn data(self, data: HashMap<&'a str, &'a str>) -> Message<'a>

Use this to add custom key-value pairs to the message. This data must be handled appropriately on the client end.

Examples:

use fcm::Message;
use std::collections::HashMap;

let mut map = HashMap::new();
map.insert("message", "Howdy!");
 
let message = Message::new("<registration id>").data(map);

fn notification(self, notification: Notification<'a>) -> Message<'a>

Use this to set a Notification for the message.

Examples:

use fcm::{Message, NotificationBuilder};

let notification = NotificationBuilder::new("Hey!")
    .body("Do you want to catch up later?")
    .finalize();
 
let message = Message::new("<registration id>")
    .notification(notification);

fn send(self, api_key: &'a str) -> Result<FcmResponseFcmError>

Send the message using your FCM API Key.

Examples:

use fcm::Message;
use std::collections::HashMap;

let mut map = HashMap::new();
map.insert("message", "Howdy!");
 
let result = Message::new("<registration id>")
    .data(map)
    .send("<FCM API Key>");

Trait Implementations

impl<'a> ToJson for Message<'a>
[src]

fn to_json(&self) -> Json

Converts the value of self to an instance of JSON