Struct a2::request::notification::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.set_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(
alert: WebPushAlert<'a>,
url_args: &'a [&'a str]
) -> WebNotificationBuilder<'a>
pub fn new( alert: WebPushAlert<'a>, url_args: &'a [&'a str] ) -> 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 set_sound(&mut self, sound: &'a str) -> &mut Self
pub fn set_sound(&mut self, sound: &'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.set_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()
);
Trait Implementations§
source§impl<'a> NotificationBuilder<'a> for WebNotificationBuilder<'a>
impl<'a> NotificationBuilder<'a> for WebNotificationBuilder<'a>
Auto Trait Implementations§
impl<'a> Freeze for WebNotificationBuilder<'a>
impl<'a> RefUnwindSafe for WebNotificationBuilder<'a>
impl<'a> Send for WebNotificationBuilder<'a>
impl<'a> Sync for WebNotificationBuilder<'a>
impl<'a> Unpin for WebNotificationBuilder<'a>
impl<'a> UnwindSafe for WebNotificationBuilder<'a>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more