zulip-api 0.0.8

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

use crate::{impl_default, impl_display};

/// Represents a legacy property for [linkifiers](crate::RealmLinkifier).
///
/// Present if `realm_filters` is present in `fetch_event_types`.
///
/// When present, this is always an empty array.
///
/// **Changes**: Prior to Zulip 7.0 (feature level 176), this was
/// an array of tuples, where each tuple described a linkifier. The first
/// element of the tuple was a string regex pattern which represented the
/// pattern to be linkified on matching, for example `"#(?P<id>[123])"`.
/// The second element was a URL format string that the pattern should be
/// linkified with. A URL format string for the above example would be
/// `"https://realm.com/my_realm_filter/%(id)s"`. And the third element
/// was the ID of the realm filter.
///
/// **Deprecated** in Zulip 4.0 (feature level 54), replaced by the
/// `realm_linkifiers` 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 RealmFilter(String, String, u64);

impl RealmFilter {
    /// Creates a new [RealmFilter].
    pub const fn new() -> Self {
        Self(String::new(), String::new(), 0)
    }

    /// Gets the regex pattern which represented the pattern to be linkified on matching, for example `"#(?P<id>[123])"`.
    pub fn linkified_regex(&self) -> &str {
        self.0.as_str()
    }

    /// Sets the regex pattern which represented the pattern to be linkified on matching, for example `"#(?P<id>[123])"`.
    pub fn set_linkified_regex(&mut self, val: String) {
        self.0 = val;
    }

    /// Builder function that sets the regex pattern which represented the pattern to be linkified on matching, for example `"#(?P<id>[123])"`.
    pub fn with_linkified_regex(self, val: String) -> Self {
        Self(val, self.1, self.2)
    }

    /// Gets the URL format string that the pattern should be linkified with.
    ///
    /// A URL format string for the above example would be `"https://realm.com/my_realm_filter/%(id)s"`.
    pub fn url_format(&self) -> &str {
        self.1.as_str()
    }

    /// Sets the URL format string that the pattern should be linkified with.
    ///
    /// A URL format string for the above example would be `"https://realm.com/my_realm_filter/%(id)s"`.
    pub fn set_url_format(&mut self, val: String) {
        self.1 = val;
    }

    /// Builder function that sets the URL format string that the pattern should be linkified with.
    ///
    /// A URL format string for the above example would be `"https://realm.com/my_realm_filter/%(id)s"`.
    pub fn with_url_format(self, val: String) -> Self {
        Self(self.0, val, self.2)
    }

    /// Gets the realm filter ID.
    pub const fn id(&self) -> u64 {
        self.2
    }

    /// Sets the realm filter ID.
    pub fn set_id(&mut self, val: u64) {
        self.2 = val;
    }

    /// Builder function that sets the realm filter ID.
    pub fn with_id(self, val: u64) -> Self {
        Self(self.0, self.1, val)
    }
}

impl_default!(RealmFilter);
impl_display!(RealmFilter);