Skip to main content

WebNotificationBuilder

Struct WebNotificationBuilder 

Source
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>

Source

pub fn new<S>( alert: WebPushAlert<'a>, url_args: &'a [S], ) -> WebNotificationBuilder<'a>
where S: Into<Cow<'a, str>> + AsRef<str>,

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

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

pub fn set_sound(&mut self, sound: impl Into<Cow<'a, str>>) -> &mut Self

👎Deprecated since 0.11.0: Use the idiomatic sound instead of the legacy set_* fn
Source

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

pub fn set_active_interruption_level(&mut self) -> &mut Self

👎Deprecated since 0.11.0: Use the idiomatic active_interruption_level instead of the legacy set_* fn
Source

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

pub fn set_critical_interruption_level(&mut self) -> &mut Self

👎Deprecated since 0.11.0: Use the idiomatic critical_interruption_level instead of the legacy set_* fn
Source

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

pub fn set_passive_interruption_level(&mut self) -> &mut Self

👎Deprecated since 0.11.0: Use the idiomatic passive_interruption_level instead of the legacy set_* fn
Source

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

pub fn set_time_sensitive_interruption_level(&mut self) -> &mut Self

👎Deprecated since 0.11.0: Use the idiomatic time_sensitive_interruption_level instead of the legacy set_* fn
Source

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

pub fn set_interruption_level(&mut self, level: InterruptionLevel) -> &mut Self

👎Deprecated since 0.11.0: Use the idiomatic interruption_level instead of the legacy set_* fn
Source

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

pub fn set_dismissal_date(&mut self, dismissal_date: u64) -> &mut Self

👎Deprecated since 0.11.0: Use the idiomatic dismissal_date instead of the legacy set_* fn

Trait Implementations§

Source§

impl<'a> NotificationBuilder<'a> for WebNotificationBuilder<'a>

Source§

fn build( self, device_token: impl Into<Cow<'a, str>>, options: NotificationOptions<'a>, ) -> Payload<'a>

Generates the request payload to be send with the Client.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more