pub struct LocalizedNotificationBuilder<'a> { /* private fields */ }
Expand description

A builder to create a localized APNs payload.

Example

let mut builder = LocalizedNotificationBuilder::new("Hi there", "What's up?");
builder.set_badge(420);
builder.set_category("cat1");
builder.set_sound("prööt");
builder.set_mutable_content();
builder.set_action_loc_key("PLAY");
builder.set_launch_image("foo.jpg");
builder.set_loc_args(&["argh", "narf"]);
builder.set_title_loc_key("STOP");
builder.set_title_loc_args(&["herp", "derp"]);
builder.set_loc_key("PAUSE");
builder.set_loc_args(&["narf", "derp"]);
let payload = builder.build("device_id", Default::default())
  .to_json_string().unwrap();

Implementations§

Creates a new builder with the minimum amount of content.

let payload = LocalizedNotificationBuilder::new("a title", "a body")
    .build("token", Default::default());

assert_eq!(
    "{\"aps\":{\"alert\":{\"body\":\"a body\",\"title\":\"a title\"},\"mutable-content\":0}}",
    &payload.to_json_string().unwrap()
);

A number to show on a badge on top of the app icon.

let mut builder = LocalizedNotificationBuilder::new("a title", "a body");
builder.set_badge(4);
let payload = builder.build("token", Default::default());

assert_eq!(
    "{\"aps\":{\"alert\":{\"body\":\"a body\",\"title\":\"a title\"},\"badge\":4,\"mutable-content\":0}}",
    &payload.to_json_string().unwrap()
);

File name of the custom sound to play when receiving the notification.

let mut builder = LocalizedNotificationBuilder::new("a title", "a body");
builder.set_sound("ping");
let payload = builder.build("token", Default::default());

assert_eq!(
    "{\"aps\":{\"alert\":{\"body\":\"a body\",\"title\":\"a title\"},\"mutable-content\":0,\"sound\":\"ping\"}}",
    &payload.to_json_string().unwrap()
);

When a notification includes the category key, the system displays the actions for that category as buttons in the banner or alert interface.

let mut builder = LocalizedNotificationBuilder::new("a title", "a body");
builder.set_category("cat1");
let payload = builder.build("token", Default::default());

assert_eq!(
    "{\"aps\":{\"alert\":{\"body\":\"a body\",\"title\":\"a title\"},\"category\":\"cat1\",\"mutable-content\":0}}",
    &payload.to_json_string().unwrap()
);

The localization key for the notification title.

let mut builder = LocalizedNotificationBuilder::new("a title", "a body");
builder.set_title_loc_key("play");
let payload = builder.build("token", Default::default());

assert_eq!(
    "{\"aps\":{\"alert\":{\"body\":\"a body\",\"title\":\"a title\",\"title-loc-key\":\"play\"},\"mutable-content\":0}}",
    &payload.to_json_string().unwrap()
);

Arguments for the title localization.

let mut builder = LocalizedNotificationBuilder::new("a title", "a body");
builder.set_title_loc_args(&["foo", "bar"]);
let payload = builder.build("token", Default::default());

assert_eq!(
    "{\"aps\":{\"alert\":{\"body\":\"a body\",\"title\":\"a title\",\"title-loc-args\":[\"foo\",\"bar\"]},\"mutable-content\":0}}",
    &payload.to_json_string().unwrap()
);

The localization key for the action.

let mut builder = LocalizedNotificationBuilder::new("a title", "a body");
builder.set_action_loc_key("stop");
let payload = builder.build("token", Default::default());

assert_eq!(
    "{\"aps\":{\"alert\":{\"action-loc-key\":\"stop\",\"body\":\"a body\",\"title\":\"a title\"},\"mutable-content\":0}}",
    &payload.to_json_string().unwrap()
);

The localization key for the push message body.

let mut builder = LocalizedNotificationBuilder::new("a title", "a body");
builder.set_loc_key("lol");
let payload = builder.build("token", Default::default());

assert_eq!(
    "{\"aps\":{\"alert\":{\"body\":\"a body\",\"loc-key\":\"lol\",\"title\":\"a title\"},\"mutable-content\":0}}",
    &payload.to_json_string().unwrap()
);

Arguments for the content localization.

let mut builder = LocalizedNotificationBuilder::new("a title", "a body");
builder.set_loc_args(&["omg", "foo"]);
let payload = builder.build("token", Default::default());

assert_eq!(
    "{\"aps\":{\"alert\":{\"body\":\"a body\",\"loc-args\":[\"omg\",\"foo\"],\"title\":\"a title\"},\"mutable-content\":0}}",
    &payload.to_json_string().unwrap()
);

Image to display in the rich notification.

let mut builder = LocalizedNotificationBuilder::new("a title", "a body");
builder.set_launch_image("cat.png");
let payload = builder.build("token", Default::default());

assert_eq!(
    "{\"aps\":{\"alert\":{\"body\":\"a body\",\"launch-image\":\"cat.png\",\"title\":\"a title\"},\"mutable-content\":0}}",
    &payload.to_json_string().unwrap()
);

Allow client to modify push content before displaying.

let mut builder = LocalizedNotificationBuilder::new("a title", "a body");
builder.set_mutable_content();
let payload = builder.build("token", Default::default());

assert_eq!(
    "{\"aps\":{\"alert\":{\"body\":\"a body\",\"title\":\"a title\"},\"mutable-content\":1}}",
    &payload.to_json_string().unwrap()
);

Trait Implementations§

Generates the request payload to be send with the Client.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.