Struct gcm::Message
[−]
[src]
pub struct Message<'a> { /* fields omitted */ }
Represents a GCM message. Construct the GCM message using various utility methods and finally send it.
Examples:
use gcm::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 gcm::{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 GCM 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>
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 GCM 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 gcm::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 gcm::{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<GcmResponse, GcmError>
Send the message using your GCM API Key.
Examples:
use gcm::Message; use std::collections::HashMap; let mut map = HashMap::new(); map.insert("message", "Howdy!"); let result = Message::new("<registration id>") .data(map) .send("<GCM API Key>");