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>

source

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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>

source§

fn clone(&self) -> DefaultNotificationBuilder<'a>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a> Debug for DefaultNotificationBuilder<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a> Default for DefaultNotificationBuilder<'a>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<'a> NotificationBuilder<'a> for DefaultNotificationBuilder<'a>

source§

fn build( self, device_token: &'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<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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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

§

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