[][src]Struct a2::request::notification::LocalizedNotificationBuilder

pub struct LocalizedNotificationBuilder<'a> { /* fields omitted */ }

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();

Methods

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

pub fn new(title: &'a str, body: &'a str) -> LocalizedNotificationBuilder<'a>[src]

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()
);

pub fn set_badge(&mut self, badge: u32) -> &mut Self[src]

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()
);

pub fn set_sound(&mut self, sound: &'a str) -> &mut Self[src]

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()
);

pub fn set_category(&mut self, category: &'a str) -> &mut Self[src]

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()
);

pub fn set_title_loc_key(&mut self, key: &'a str) -> &mut Self[src]

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()
);

pub fn set_title_loc_args<S>(&mut self, args: &'a [S]) -> &mut Self where
    S: Into<Cow<'a, str>> + AsRef<str>, 
[src]

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()
);

pub fn set_action_loc_key(&mut self, key: &'a str) -> &mut Self[src]

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()
);

pub fn set_loc_key(&mut self, key: &'a str) -> &mut Self[src]

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()
);

pub fn set_loc_args<S>(&mut self, args: &'a [S]) -> &mut Self where
    S: Into<Cow<'a, str>> + AsRef<str>, 
[src]

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()
);

pub fn set_launch_image(&mut self, image: &'a str) -> &mut Self[src]

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()
);

pub fn set_mutable_content(&mut self) -> &mut Self[src]

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

impl<'a> NotificationBuilder<'a> for LocalizedNotificationBuilder<'a>[src]

Auto Trait Implementations

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Erased for T