bark_apns/lib.rs
1//! Direct APNs client for sending [Bark](https://github.com/Finb/Bark)
2//! notifications.
3//!
4//! This crate talks to Apple Push Notification service directly with an iOS
5//! device token. It does not call a Bark server, but it keeps Bark's payload
6//! semantics: fields such as `title`, `body`, `markdown`, `sound`, `group`,
7//! `isArchive`, `id`, and `delete` are encoded the way Bark's notification
8//! service extension expects them.
9//!
10//! # Examples
11//!
12//! ## Send a Simple Message
13//!
14//! ```no_run
15//! use bark_apns::{Bark, Message};
16//!
17//! fn main() -> bark_apns::Result<()> {
18//! let bark = Bark::new()?;
19//! let message = Message::new()
20//! .title("Deploy")
21//! .body("done")
22//! .group("ops");
23//!
24//! bark.send(&message, ["device-token-from-bark-app"])?;
25//! Ok(())
26//! }
27//! ```
28//!
29//! ## Send a Markdown Message
30//!
31//! ```no_run
32//! use bark_apns::{Bark, Message};
33//!
34//! fn main() -> bark_apns::Result<()> {
35//! let bark = Bark::new()?;
36//! let message = Message::new()
37//! .title("Deploy")
38//! .markdown("## Deploy\n\n- status: **done**\n- target: `production`");
39//!
40//! bark.send(&message, ["device-token-from-bark-app"])?;
41//! Ok(())
42//! }
43//! ```
44//!
45//! ## Send an Encrypted Message
46//!
47//! ```no_run
48//! use bark_apns::{Bark, Encryption, EncryptionAlgorithm, EncryptionMode, Message};
49//!
50//! fn main() -> bark_apns::Result<()> {
51//! let bark = Bark::new()?;
52//! let encryption = Encryption::new(
53//! EncryptionAlgorithm::AES128,
54//! EncryptionMode::CBC,
55//! "1234567890123456",
56//! )?;
57//!
58//! let message = Message::new()
59//! .title("Deploy")
60//! .body("done")
61//! .markdown("**Deploy** finished")
62//! .group("ops")
63//! .encryption(encryption);
64//!
65//! bark.send(&message, ["device-token-from-bark-app"])?;
66//! Ok(())
67//! }
68//! ```
69//!
70//! # Notes
71//!
72//! - `markdown` follows Bark's documented behavior: when present, Bark renders it
73//! and ignores `body` for display.
74//! - Bark parses Markdown with Apple's Swift Markdown package and its own
75//! renderer. It supports paragraphs, headings, block quotes, bold, italic,
76//! strikethrough, inline code, code blocks, links, images, ordered and
77//! unordered lists, nested lists, task-list checkboxes, soft breaks, and hard
78//! line breaks. In notification banners, Bark uses the rendered plain-text body
79//! and collapses repeated blank lines, so styling such as bold, italic, link
80//! color, and code font is not preserved there.
81//! - Encrypted pushes serialize Bark request fields to JSON, encrypt that JSON,
82//! and put the result in the top-level `ciphertext` field. CBC and GCM pushes
83//! also include a top-level `iv`, matching Bark's client-side decryptor.
84
85#![warn(missing_docs)]
86
87mod apns;
88mod crypto;
89mod error;
90mod message;
91
92pub use apns::Bark;
93pub use crypto::{Encryption, EncryptionAlgorithm, EncryptionMode};
94pub use error::{Error, Result};
95pub use message::{InterruptionLevel, Message};