barkust 0.1.0

A Rust client library and CLI for the Bark push notification service
Documentation
use crate::{Level, Notification};

/// A builder for constructing [`Notification`] values.
#[derive(Debug, Default, Clone)]
pub struct NotificationBuilder {
    device_key: Option<String>,
    title: Option<String>,
    body: Option<String>,
    sound: Option<String>,
    badge: Option<i32>,
    icon: Option<String>,
    group: Option<String>,
    url: Option<String>,
    copy: Option<String>,
    action: Option<String>,
    is_archive: Option<i32>,
    is_url_encode: Option<i32>,
    auto_copy: Option<i32>,
    level: Option<Level>,
    volume: Option<i32>,
    call: Option<i32>,
}

impl NotificationBuilder {
    /// Create a new, empty builder.
    pub fn new() -> Self {
        Self::default()
    }

    /// Set the target device key.
    pub fn device_key(mut self, key: impl Into<String>) -> Self {
        self.device_key = Some(key.into());
        self
    }

    /// Set the notification title.
    pub fn title(mut self, title: impl Into<String>) -> Self {
        self.title = Some(title.into());
        self
    }

    /// Set the notification body.
    pub fn body(mut self, body: impl Into<String>) -> Self {
        self.body = Some(body.into());
        self
    }

    /// Set the alert sound name.
    pub fn sound(mut self, sound: impl Into<String>) -> Self {
        self.sound = Some(sound.into());
        self
    }

    /// Set the badge number.
    pub fn badge(mut self, badge: i32) -> Self {
        self.badge = Some(badge);
        self
    }

    /// Set the icon URL.
    pub fn icon(mut self, icon: impl Into<String>) -> Self {
        self.icon = Some(icon.into());
        self
    }

    /// Set the notification group name.
    pub fn group(mut self, group: impl Into<String>) -> Self {
        self.group = Some(group.into());
        self
    }

    /// Set the URL to open when the notification is tapped.
    pub fn url(mut self, url: impl Into<String>) -> Self {
        self.url = Some(url.into());
        self
    }

    /// Set the text copied to the clipboard when the notification is tapped.
    pub fn copy(mut self, copy: impl Into<String>) -> Self {
        self.copy = Some(copy.into());
        self
    }

    /// Set a custom action (iOS notification action identifier).
    pub fn action(mut self, action: impl Into<String>) -> Self {
        self.action = Some(action.into());
        self
    }

    /// Whether to archive the notification in Bark history.
    pub fn archive(mut self, archive: bool) -> Self {
        self.is_archive = Some(if archive { 1 } else { 0 });
        self
    }

    /// Whether the title and body should be URL-encoded by the server.
    pub fn url_encode(mut self, encode: bool) -> Self {
        self.is_url_encode = Some(if encode { 1 } else { 0 });
        self
    }

    /// Whether to automatically copy `copy` text when the notification arrives.
    pub fn auto_copy(mut self, auto_copy: bool) -> Self {
        self.auto_copy = Some(if auto_copy { 1 } else { 0 });
        self
    }

    /// Set the interruption level of the notification.
    pub fn level(mut self, level: Level) -> Self {
        self.level = Some(level);
        self
    }

    /// Set the volume for the alert sound (0-10).
    pub fn volume(mut self, volume: i32) -> Self {
        self.volume = Some(volume);
        self
    }

    /// Whether to call the user after delivering the notification.
    pub fn call(mut self, call: bool) -> Self {
        self.call = Some(if call { 1 } else { 0 });
        self
    }

    /// Build the [`Notification`].
    pub fn build(self) -> Notification {
        Notification {
            device_key: self.device_key,
            title: self.title,
            body: self.body,
            sound: self.sound,
            badge: self.badge,
            icon: self.icon,
            group: self.group,
            url: self.url,
            copy: self.copy,
            action: self.action,
            is_archive: self.is_archive,
            is_url_encode: self.is_url_encode,
            auto_copy: self.auto_copy,
            level: self.level,
            volume: self.volume,
            call: self.call,
        }
    }
}