Struct a2::request::notification::DefaultNotificationBuilder
source · pub struct DefaultNotificationBuilder<'a> { /* private fields */ }
Expand description
A builder to create an APNs payload.
§Example
let mut builder = DefaultNotificationBuilder::new()
.set_title("Hi there")
.set_subtitle("From bob")
.set_body("What's up?")
.set_badge(420)
.set_category("cat1")
.set_sound("prööt")
.set_critical(false, None)
.set_mutable_content()
.set_action_loc_key("PLAY")
.set_launch_image("foo.jpg")
.set_loc_args(&["argh", "narf"])
.set_title_loc_key("STOP")
.set_title_loc_args(&["herp", "derp"])
.set_loc_key("PAUSE")
.set_loc_args(&["narf", "derp"]);
let payload = builder.build("device_id", Default::default())
.to_json_string().unwrap();
Implementations§
source§impl<'a> DefaultNotificationBuilder<'a>
impl<'a> DefaultNotificationBuilder<'a>
sourcepub fn new() -> DefaultNotificationBuilder<'a>
pub fn new() -> DefaultNotificationBuilder<'a>
Creates a new builder with the minimum amount of content.
let payload = DefaultNotificationBuilder::new()
.set_title("a title")
.set_body("a body")
.build("token", Default::default());
assert_eq!(
"{\"aps\":{\"alert\":{\"title\":\"a title\",\"body\":\"a body\"},\"mutable-content\":0}}",
&payload.to_json_string().unwrap()
);
sourcepub fn set_title(self, title: &'a str) -> Self
pub fn set_title(self, title: &'a str) -> Self
Set the title of the notification. Apple Watch displays this string in the short look notification interface. Specify a string that’s quickly understood by the user.
let mut builder = DefaultNotificationBuilder::new()
.set_title("a title");
let payload = builder.build("token", Default::default());
assert_eq!(
"{\"aps\":{\"alert\":{\"title\":\"a title\"},\"mutable-content\":0}}",
&payload.to_json_string().unwrap()
);
sourcepub fn set_critical(self, critical: bool, volume: Option<f64>) -> Self
pub fn set_critical(self, critical: bool, volume: Option<f64>) -> Self
Set critical alert value for this notification
Volume can only be set when the notification is marked as critcial
Note: You’ll need the critical alerts entitlement to use true
!
let mut builder = DefaultNotificationBuilder::new()
.set_critical(true, None);
let payload = builder.build("token", Default::default());
assert_eq!(
"{\"aps\":{\"sound\":{\"critical\":1},\"mutable-content\":0}}",
&payload.to_json_string().unwrap()
);
sourcepub fn set_subtitle(self, subtitle: &'a str) -> Self
pub fn set_subtitle(self, subtitle: &'a str) -> Self
Used to set the subtitle which should provide additional information that explains the purpose of the notification.
let mut builder = DefaultNotificationBuilder::new()
.set_subtitle("a subtitle");
let payload = builder.build("token", Default::default());
assert_eq!(
"{\"aps\":{\"alert\":{\"subtitle\":\"a subtitle\"},\"mutable-content\":0}}",
&payload.to_json_string().unwrap()
);
sourcepub fn set_body(self, body: &'a str) -> Self
pub fn set_body(self, body: &'a str) -> Self
Sets the content of the alert message.
let mut builder = DefaultNotificationBuilder::new()
.set_body("a body");
let payload = builder.build("token", Default::default());
assert_eq!(
"{\"aps\":{\"alert\":\"a body\",\"mutable-content\":0}}",
&payload.to_json_string().unwrap()
);
sourcepub fn set_badge(self, badge: u32) -> Self
pub fn set_badge(self, badge: u32) -> Self
A number to show on a badge on top of the app icon.
let mut builder = DefaultNotificationBuilder::new()
.set_badge(4);
let payload = builder.build("token", Default::default());
assert_eq!(
"{\"aps\":{\"badge\":4,\"mutable-content\":0}}",
&payload.to_json_string().unwrap()
);
sourcepub fn set_sound(self, sound: &'a str) -> Self
pub fn set_sound(self, sound: &'a str) -> Self
File name of the custom sound to play when receiving the notification.
let mut builder = DefaultNotificationBuilder::new()
.set_title("a title")
.set_sound("ping");
let payload = builder.build("token", Default::default());
assert_eq!(
"{\"aps\":{\"alert\":{\"title\":\"a title\"},\"sound\":\"ping\",\"mutable-content\":0}}",
&payload.to_json_string().unwrap()
);
sourcepub fn set_category(self, category: &'a str) -> Self
pub fn set_category(self, category: &'a str) -> Self
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 = DefaultNotificationBuilder::new()
.set_title("a title")
.set_category("cat1");
let payload = builder.build("token", Default::default());
assert_eq!(
"{\"aps\":{\"alert\":{\"title\":\"a title\"},\"category\":\"cat1\",\"mutable-content\":0}}",
&payload.to_json_string().unwrap()
);
sourcepub fn set_title_loc_key(self, key: &'a str) -> Self
pub fn set_title_loc_key(self, key: &'a str) -> Self
The localization key for the notification title.
let mut builder = DefaultNotificationBuilder::new()
.set_title("a title")
.set_title_loc_key("play");
let payload = builder.build("token", Default::default());
assert_eq!(
"{\"aps\":{\"alert\":{\"title\":\"a title\",\"title-loc-key\":\"play\"},\"mutable-content\":0}}",
&payload.to_json_string().unwrap()
);
sourcepub fn set_title_loc_args<S>(self, args: &'a [S]) -> Self
pub fn set_title_loc_args<S>(self, args: &'a [S]) -> Self
Arguments for the title localization.
let mut builder = DefaultNotificationBuilder::new()
.set_title("a title")
.set_title_loc_args(&["foo", "bar"]);
let payload = builder.build("token", Default::default());
assert_eq!(
"{\"aps\":{\"alert\":{\"title\":\"a title\",\"title-loc-args\":[\"foo\",\"bar\"]},\"mutable-content\":0}}",
&payload.to_json_string().unwrap()
);
sourcepub fn set_action_loc_key(self, key: &'a str) -> Self
pub fn set_action_loc_key(self, key: &'a str) -> Self
The localization key for the action.
let mut builder = DefaultNotificationBuilder::new()
.set_title("a title")
.set_action_loc_key("stop");
let payload = builder.build("token", Default::default());
assert_eq!(
"{\"aps\":{\"alert\":{\"title\":\"a title\",\"action-loc-key\":\"stop\"},\"mutable-content\":0}}",
&payload.to_json_string().unwrap()
);
sourcepub fn set_loc_key(self, key: &'a str) -> Self
pub fn set_loc_key(self, key: &'a str) -> Self
The localization key for the push message body.
let mut builder = DefaultNotificationBuilder::new()
.set_title("a title")
.set_loc_key("lol");
let payload = builder.build("token", Default::default());
assert_eq!(
"{\"aps\":{\"alert\":{\"title\":\"a title\",\"loc-key\":\"lol\"},\"mutable-content\":0}}",
&payload.to_json_string().unwrap()
);
sourcepub fn set_loc_args<S>(self, args: &'a [S]) -> Self
pub fn set_loc_args<S>(self, args: &'a [S]) -> Self
Arguments for the content localization.
let mut builder = DefaultNotificationBuilder::new()
.set_title("a title")
.set_loc_args(&["omg", "foo"]);
let payload = builder.build("token", Default::default());
assert_eq!(
"{\"aps\":{\"alert\":{\"title\":\"a title\",\"loc-args\":[\"omg\",\"foo\"]},\"mutable-content\":0}}",
&payload.to_json_string().unwrap()
);
sourcepub fn set_launch_image(self, image: &'a str) -> Self
pub fn set_launch_image(self, image: &'a str) -> Self
Image to display in the rich notification.
let mut builder = DefaultNotificationBuilder::new()
.set_title("a title")
.set_launch_image("cat.png");
let payload = builder.build("token", Default::default());
assert_eq!(
"{\"aps\":{\"alert\":{\"title\":\"a title\",\"launch-image\":\"cat.png\"},\"mutable-content\":0}}",
&payload.to_json_string().unwrap()
);
sourcepub fn set_mutable_content(self) -> Self
pub fn set_mutable_content(self) -> Self
Allow client to modify push content before displaying.
let mut builder = DefaultNotificationBuilder::new()
.set_title("a title")
.set_mutable_content();
let payload = builder.build("token", Default::default());
assert_eq!(
"{\"aps\":{\"alert\":{\"title\":\"a title\"},\"mutable-content\":1}}",
&payload.to_json_string().unwrap()
);
sourcepub fn set_content_available(self) -> Self
pub fn set_content_available(self) -> Self
Used for adding custom data to push notifications
let mut builder = DefaultNotificationBuilder::new()
.set_title("a title")
.set_content_available();
let payload = builder.build("token", Default::default());
assert_eq!(
"{\"aps\":{\"alert\":{\"title\":\"a title\"},\"content-available\":1,\"mutable-content\":0}}",
&payload.to_json_string().unwrap()
);
Trait Implementations§
source§impl<'a> Clone for DefaultNotificationBuilder<'a>
impl<'a> Clone for DefaultNotificationBuilder<'a>
source§fn clone(&self) -> DefaultNotificationBuilder<'a>
fn clone(&self) -> DefaultNotificationBuilder<'a>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more