zulip-api 0.0.8

Client library for interacting with the Zulip API
Documentation
use serde::{Deserialize, Serialize};

use crate::{field_access, impl_default, impl_display};

/// Represents the details of a push device with the push account ID as the key.
///
/// Modified from `openapi-generator-cli` output:
///
/// ```shell,no_build,no_run
/// $ openapi-generator-cli generate -g rust -i ./zerver/openapi/zulip.yaml -o zulip-openapi --skip-validate-spec
/// ```
///
/// ```text
/// /*
/// * Zulip REST API
/// *
/// * Powerful open source group chat
/// *
/// * The version of the OpenAPI document: 1.0.0
/// *
/// * Generated by: https://openapi-generator.tech
/// */
/// ```
///
/// See [zerver/openapi/zulip.yaml](https://github.com/zulip/zulip/blob/main/zerver/openapi/zulip.yaml) for the original OpenAPI configuration.
///
/// Configuration slightly modified to work with the Rust generator of [`openapi-generator-cli`](https://openapi-generator.tech).
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct PushDevice {
    #[serde(skip_serializing_if = "Option::is_none")]
    status: Option<PushDeviceStatus>,
    #[serde(skip_serializing_if = "Option::is_none")]
    error_code: Option<String>,
}

impl PushDevice {
    /// Creates a new [PushDevice].
    pub fn new() -> Self {
        Self {
            status: None,
            error_code: None,
        }
    }
}

field_access! {
    PushDevice {
        /// The push account's registration status.
        status: option { PushDeviceStatus },
    }
}

field_access! {
    PushDevice {
        /// If the status is `\"failed\"`, a [Zulip API error code](https://zulip.com/api/rest-error-handling) indicating the type of failure that occurred.
        ///
        /// The following error codes have recommended client behavior:
        ///
        /// - `\"INVALID_BOUNCER_PUBLIC_KEY\"`: Inform the user to update app.
        /// - `\"REQUEST_EXPIRED`: Retry with a fresh payload.
        error_code: option_cow_deref { str, String },
    }
}

impl_default!(PushDevice);
impl_display!(PushDevice);

/// Represents the push account's registration status.
///
/// Either:
///
/// - `\"active\"`
/// - `\"pending\"`
/// - `\"failed\"`
#[derive(Clone, Copy, Debug, Eq, PartialEq, Deserialize, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum PushDeviceStatus {
    Active,
    Pending,
    Failed,
}

impl PushDeviceStatus {
    /// Creates a new [PushDeviceStatus].
    pub const fn new() -> Self {
        Self::Active
    }
}

impl_default!(PushDeviceStatus);
impl_display!(PushDeviceStatus);