pub struct WebNotificationBuilder<'a> { /* private fields */ }Expand description
A builder to create a simple APNs notification payload.
§Example
let mut builder = WebNotificationBuilder::new(WebPushAlert {title: "Hello", body: "World", action: "View"}, &["arg1"]);
builder.sound("prööt");
let payload = builder.build("device_id", Default::default())
.to_json_string().unwrap();Implementations§
Source§impl<'a> WebNotificationBuilder<'a>
impl<'a> WebNotificationBuilder<'a>
Sourcepub fn new<S>(
alert: WebPushAlert<'a>,
url_args: &'a [S],
) -> WebNotificationBuilder<'a>
pub fn new<S>( alert: WebPushAlert<'a>, url_args: &'a [S], ) -> WebNotificationBuilder<'a>
Creates a new builder with the minimum amount of content.
let mut builder = WebNotificationBuilder::new(WebPushAlert {title: "Hello", body: "World", action: "View"}, &["arg1"]);
let payload = builder.build("token", Default::default());
assert_eq!(
"{\"aps\":{\"alert\":{\"title\":\"Hello\",\"body\":\"World\",\"action\":\"View\"},\"url-args\":[\"arg1\"]}}",
&payload.to_json_string().unwrap()
);Sourcepub fn sound(&mut self, sound: impl Into<Cow<'a, str>>) -> &mut Self
pub fn sound(&mut self, sound: impl Into<Cow<'a, str>>) -> &mut Self
File name of the custom sound to play when receiving the notification.
let mut builder = WebNotificationBuilder::new(WebPushAlert {title: "Hello", body: "World", action: "View"}, &["arg1"]);
builder.sound("meow");
let payload = builder.build("token", Default::default());
assert_eq!(
"{\"aps\":{\"alert\":{\"title\":\"Hello\",\"body\":\"World\",\"action\":\"View\"},\"sound\":\"meow\",\"url-args\":[\"arg1\"]}}",
&payload.to_json_string().unwrap()
);pub fn set_sound(&mut self, sound: impl Into<Cow<'a, str>>) -> &mut Self
sound instead of the legacy set_* fnSourcepub fn active_interruption_level(&mut self) -> &mut Self
pub fn active_interruption_level(&mut self) -> &mut Self
Set the interruption level to active. The system presents the notification immediately, lights up the screen, and can play a sound.
let mut builder = WebNotificationBuilder::new(WebPushAlert {title: "Hello", body: "World", action: "View"}, &["arg1"]);
builder.active_interruption_level();
let payload = builder.build("token", Default::default());
assert_eq!(
"{\"aps\":{\"alert\":{\"title\":\"Hello\",\"body\":\"World\",\"action\":\"View\"},\"interruption-level\":\"active\",\"url-args\":[\"arg1\"]}}",
&payload.to_json_string().unwrap()
);pub fn set_active_interruption_level(&mut self) -> &mut Self
active_interruption_level instead of the legacy set_* fnSourcepub fn critical_interruption_level(&mut self) -> &mut Self
pub fn critical_interruption_level(&mut self) -> &mut Self
Set the interruption level to critical. The system presents the notification immediately, lights up the screen, and bypasses the mute switch to play a sound.
let mut builder = WebNotificationBuilder::new(WebPushAlert {title: "Hello", body: "World", action: "View"}, &["arg1"]);
builder.critical_interruption_level();
let payload = builder.build("token", Default::default());
assert_eq!(
"{\"aps\":{\"alert\":{\"title\":\"Hello\",\"body\":\"World\",\"action\":\"View\"},\"interruption-level\":\"critical\",\"url-args\":[\"arg1\"]}}",
&payload.to_json_string().unwrap()
);pub fn set_critical_interruption_level(&mut self) -> &mut Self
critical_interruption_level instead of the legacy set_* fnSourcepub fn passive_interruption_level(&mut self) -> &mut Self
pub fn passive_interruption_level(&mut self) -> &mut Self
Set the interruption level to passive. The system adds the notification to the notification list without lighting up the screen or playing a sound.
let mut builder = WebNotificationBuilder::new(WebPushAlert {title: "Hello", body: "World", action: "View"}, &["arg1"]);
builder.passive_interruption_level();
let payload = builder.build("token", Default::default());
assert_eq!(
"{\"aps\":{\"alert\":{\"title\":\"Hello\",\"body\":\"World\",\"action\":\"View\"},\"interruption-level\":\"passive\",\"url-args\":[\"arg1\"]}}",
&payload.to_json_string().unwrap()
);pub fn set_passive_interruption_level(&mut self) -> &mut Self
passive_interruption_level instead of the legacy set_* fnSourcepub fn time_sensitive_interruption_level(&mut self) -> &mut Self
pub fn time_sensitive_interruption_level(&mut self) -> &mut Self
Set the interruption level to time sensitive. The system presents the notification immediately, lights up the screen, can play a sound, and breaks through system notification controls.
let mut builder = WebNotificationBuilder::new(WebPushAlert {title: "Hello", body: "World", action: "View"}, &["arg1"]);
builder.time_sensitive_interruption_level();
let payload = builder.build("token", Default::default());
assert_eq!(
"{\"aps\":{\"alert\":{\"title\":\"Hello\",\"body\":\"World\",\"action\":\"View\"},\"interruption-level\":\"time-sensitive\",\"url-args\":[\"arg1\"]}}",
&payload.to_json_string().unwrap()
);pub fn set_time_sensitive_interruption_level(&mut self) -> &mut Self
time_sensitive_interruption_level instead of the legacy set_* fnSourcepub fn interruption_level(&mut self, level: InterruptionLevel) -> &mut Self
pub fn interruption_level(&mut self, level: InterruptionLevel) -> &mut Self
Set the interruption level directly. Controls how the notification is presented to the user.
let mut builder = WebNotificationBuilder::new(WebPushAlert {title: "Hello", body: "World", action: "View"}, &["arg1"]);
builder.interruption_level(InterruptionLevel::Active);
let payload = builder.build("token", Default::default());
assert_eq!(
"{\"aps\":{\"alert\":{\"title\":\"Hello\",\"body\":\"World\",\"action\":\"View\"},\"interruption-level\":\"active\",\"url-args\":[\"arg1\"]}}",
&payload.to_json_string().unwrap()
);pub fn set_interruption_level(&mut self, level: InterruptionLevel) -> &mut Self
interruption_level instead of the legacy set_* fnSourcepub fn dismissal_date(&mut self, dismissal_date: u64) -> &mut Self
pub fn dismissal_date(&mut self, dismissal_date: u64) -> &mut Self
Set the dismissal date for when the system should automatically remove the notification. The timestamp should be in Unix epoch time (seconds since 1970-01-01 00:00:00 UTC).
let mut builder = WebNotificationBuilder::new(WebPushAlert {title: "Hello", body: "World", action: "View"}, &["arg1"]);
builder.dismissal_date(1672531200); // January 1, 2023 00:00:00 UTC
let payload = builder.build("token", Default::default());
assert_eq!(
"{\"aps\":{\"alert\":{\"title\":\"Hello\",\"body\":\"World\",\"action\":\"View\"},\"dismissal-date\":1672531200,\"url-args\":[\"arg1\"]}}",
&payload.to_json_string().unwrap()
);pub fn set_dismissal_date(&mut self, dismissal_date: u64) -> &mut Self
dismissal_date instead of the legacy set_* fn