zulip-api 0.0.8

Client library for interacting with the Zulip API
Documentation
use crate::{impl_default, impl_display};

/// Represents the Zulip API endpoint variants.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Endpoint {
    /// Represents the `Send Message` API endpoint.
    SendMessage,
    /// Represents the `Get Messages` API endpoint.
    GetMessages,
    /// Represents the `Upload File` API endpoint.
    UploadFile,
    /// Represents the `Resumable Upload File` API endpoint.
    ResumableUploadFile,
    /// Represents the `Edit Message` API endpoint.
    EditMessage,
    /// Represents the `Delete Message` API endpoint.
    DeleteMessage,
    /// Represents the `Get Message` API endpoint.
    GetMessage,
    /// Represents the `Get Message History` API endpoint.
    GetMessageHistory,
    /// Represents the `Report Message` API endpoint.
    ReportMessage,
    /// Represents the `Matches Narrow` API endpoint.
    MatchesNarrow,
    /// Represents the `Register` API endpoint.
    Register,
    /// Represents the `Reactions` API endpoint.
    Reaction,
    /// Represents the `Render` API endpoint.
    Render,
    /// Represents the `Fetch API Key` API endpoint.
    FetchApiKey,
    /// Represents the `Update Message Flags` API endpoint.
    UpdateMessageFlags,
    /// Represents the `Update Message Flags for Narrow` API endpoint.
    UpdateMessageFlagsNarrow,
    /// Represents the `Mark All as Read` API endpoint.
    MarkAllAsRead,
    /// Represents the `Mark Stream as Read` API endpoint.
    MarkStreamAsRead,
    /// Represents the `Mark Topic as Read` API endpoint.
    MarkTopicAsRead,
}

impl Endpoint {
    /// Represents the string value for the `Send Message` endpoint.
    pub const SEND_MESSAGE: &str = "api/v1/messages";
    /// Represents the string value for the `Get Messages` endpoint.
    pub const GET_MESSAGES: &str = "api/v1/messages";
    /// Represents the string value for the `Upload File` endpoint.
    pub const UPLOAD_FILE: &str = "api/v1/user_uploads";
    /// Represents the string value for the `Resumable Upload File` endpoint.
    pub const RESUMABLE_UPLOAD_FILE: &str = "api/v1/tus";
    /// Represents the string value for the `Edit Message` endpoint.
    pub const EDIT_MESSAGE: &str = "api/v1/messages";
    /// Represents the string value for the `Delete Message` endpoint.
    pub const DELETE_MESSAGE: &str = "api/v1/messages";
    /// Represents the string value for the `Get Message` endpoint.
    pub const GET_MESSAGE: &str = "api/v1/messages";
    /// Represents the string value for the `Get Message History` endpoint.
    pub const GET_MESSAGE_HISTORY: &str = "api/v1/messages";
    /// Represents the string value for the `Report Message` endpoint.
    pub const REPORT_MESSAGE: &str = "api/v1/messages";
    /// Represents the string value for the `Matches Narrow` endpoint.
    pub const MATCHES_NARROW: &str = "api/v1/messages/matches_narrow";
    /// Represents the string value for the `Register` endpoint.
    pub const REGISTER: &str = "api/v1/register";
    /// Represents the string value for the `Reactions` endpoint.
    pub const REACTION: &str = "api/v1/messages";
    /// Represents the string value for the `Render` endpoint.
    pub const RENDER: &str = "api/v1/messages/render";
    /// Represents the string value for the `Fetch API Key` endpoint.
    pub const FETCH_API_KEY: &str = "api/v1/fetch_api_key";
    /// Represents the string value for the `Update Message Flags` endpoint.
    pub const UPDATE_MESSAGE_FLAGS: &str = "api/v1/messages/flags";
    /// Represents the string value for the `Update Message Flags for Narrow` endpoint.
    pub const UPDATE_MESSAGE_FLAGS_NARROW: &str = "api/v1/messages/flags/narrow";
    /// Represents the string value for the `Mark All as Read` endpoint.
    pub const MARK_ALL_AS_READ: &str = "api/v1/mark_all_as_read";
    /// Represents the string value for the `Mark Stream as Read` endpoint.
    pub const MARK_STREAM_AS_READ: &str = "api/v1/mark_stream_as_read";
    /// Represents the string value for the `Mark Topic as Read` endpoint.
    pub const MARK_TOPIC_AS_READ: &str = "api/v1/mark_topic_as_read";

    /// Creates a new [Endpoint].
    pub const fn new() -> Self {
        Self::SendMessage
    }

    /// Gets the string representation of the [Endpoint].
    pub const fn as_str(&self) -> &'static str {
        match self {
            Self::SendMessage => Self::SEND_MESSAGE,
            Self::GetMessages => Self::GET_MESSAGES,
            Self::UploadFile => Self::UPLOAD_FILE,
            Self::ResumableUploadFile => Self::RESUMABLE_UPLOAD_FILE,
            Self::EditMessage => Self::EDIT_MESSAGE,
            Self::DeleteMessage => Self::DELETE_MESSAGE,
            Self::GetMessage => Self::GET_MESSAGE,
            Self::GetMessageHistory => Self::GET_MESSAGE_HISTORY,
            Self::ReportMessage => Self::REPORT_MESSAGE,
            Self::MatchesNarrow => Self::MATCHES_NARROW,
            Self::Register => Self::REGISTER,
            Self::Reaction => Self::REACTION,
            Self::Render => Self::RENDER,
            Self::FetchApiKey => Self::FETCH_API_KEY,
            Self::UpdateMessageFlags => Self::UPDATE_MESSAGE_FLAGS,
            Self::UpdateMessageFlagsNarrow => Self::UPDATE_MESSAGE_FLAGS_NARROW,
            Self::MarkAllAsRead => Self::MARK_ALL_AS_READ,
            Self::MarkStreamAsRead => Self::MARK_STREAM_AS_READ,
            Self::MarkTopicAsRead => Self::MARK_TOPIC_AS_READ,
        }
    }
}

impl From<Endpoint> for &'static str {
    fn from(val: Endpoint) -> Self {
        val.as_str()
    }
}

impl From<Endpoint> for String {
    fn from(val: Endpoint) -> Self {
        val.as_str().to_string()
    }
}

impl_default!(Endpoint);
impl_display!(Endpoint: str);