Skip to main content

zulip_api/client/
endpoint.rs

1use crate::{impl_default, impl_display};
2
3/// Represents the Zulip API endpoint variants.
4#[derive(Clone, Copy, Debug, Eq, PartialEq)]
5pub enum Endpoint {
6    /// Represents the `Send Message` API endpoint.
7    SendMessage,
8    /// Represents the `Get Messages` API endpoint.
9    GetMessages,
10    /// Represents the `Upload File` API endpoint.
11    UploadFile,
12    /// Represents the `Resumable Upload File` API endpoint.
13    ResumableUploadFile,
14    /// Represents the `Edit Message` API endpoint.
15    EditMessage,
16    /// Represents the `Delete Message` API endpoint.
17    DeleteMessage,
18    /// Represents the `Get Message` API endpoint.
19    GetMessage,
20    /// Represents the `Get Message History` API endpoint.
21    GetMessageHistory,
22    /// Represents the `Report Message` API endpoint.
23    ReportMessage,
24    /// Represents the `Matches Narrow` API endpoint.
25    MatchesNarrow,
26    /// Represents the `Register` API endpoint.
27    Register,
28    /// Represents the `Reactions` API endpoint.
29    Reaction,
30    /// Represents the `Render` API endpoint.
31    Render,
32    /// Represents the `Fetch API Key` API endpoint.
33    FetchApiKey,
34    /// Represents the `Update Message Flags` API endpoint.
35    UpdateMessageFlags,
36    /// Represents the `Update Message Flags for Narrow` API endpoint.
37    UpdateMessageFlagsNarrow,
38    /// Represents the `Mark All as Read` API endpoint.
39    MarkAllAsRead,
40    /// Represents the `Mark Stream as Read` API endpoint.
41    MarkStreamAsRead,
42    /// Represents the `Mark Topic as Read` API endpoint.
43    MarkTopicAsRead,
44}
45
46impl Endpoint {
47    /// Represents the string value for the `Send Message` endpoint.
48    pub const SEND_MESSAGE: &str = "api/v1/messages";
49    /// Represents the string value for the `Get Messages` endpoint.
50    pub const GET_MESSAGES: &str = "api/v1/messages";
51    /// Represents the string value for the `Upload File` endpoint.
52    pub const UPLOAD_FILE: &str = "api/v1/user_uploads";
53    /// Represents the string value for the `Resumable Upload File` endpoint.
54    pub const RESUMABLE_UPLOAD_FILE: &str = "api/v1/tus";
55    /// Represents the string value for the `Edit Message` endpoint.
56    pub const EDIT_MESSAGE: &str = "api/v1/messages";
57    /// Represents the string value for the `Delete Message` endpoint.
58    pub const DELETE_MESSAGE: &str = "api/v1/messages";
59    /// Represents the string value for the `Get Message` endpoint.
60    pub const GET_MESSAGE: &str = "api/v1/messages";
61    /// Represents the string value for the `Get Message History` endpoint.
62    pub const GET_MESSAGE_HISTORY: &str = "api/v1/messages";
63    /// Represents the string value for the `Report Message` endpoint.
64    pub const REPORT_MESSAGE: &str = "api/v1/messages";
65    /// Represents the string value for the `Matches Narrow` endpoint.
66    pub const MATCHES_NARROW: &str = "api/v1/messages/matches_narrow";
67    /// Represents the string value for the `Register` endpoint.
68    pub const REGISTER: &str = "api/v1/register";
69    /// Represents the string value for the `Reactions` endpoint.
70    pub const REACTION: &str = "api/v1/messages";
71    /// Represents the string value for the `Render` endpoint.
72    pub const RENDER: &str = "api/v1/messages/render";
73    /// Represents the string value for the `Fetch API Key` endpoint.
74    pub const FETCH_API_KEY: &str = "api/v1/fetch_api_key";
75    /// Represents the string value for the `Update Message Flags` endpoint.
76    pub const UPDATE_MESSAGE_FLAGS: &str = "api/v1/messages/flags";
77    /// Represents the string value for the `Update Message Flags for Narrow` endpoint.
78    pub const UPDATE_MESSAGE_FLAGS_NARROW: &str = "api/v1/messages/flags/narrow";
79    /// Represents the string value for the `Mark All as Read` endpoint.
80    pub const MARK_ALL_AS_READ: &str = "api/v1/mark_all_as_read";
81    /// Represents the string value for the `Mark Stream as Read` endpoint.
82    pub const MARK_STREAM_AS_READ: &str = "api/v1/mark_stream_as_read";
83    /// Represents the string value for the `Mark Topic as Read` endpoint.
84    pub const MARK_TOPIC_AS_READ: &str = "api/v1/mark_topic_as_read";
85
86    /// Creates a new [Endpoint].
87    pub const fn new() -> Self {
88        Self::SendMessage
89    }
90
91    /// Gets the string representation of the [Endpoint].
92    pub const fn as_str(&self) -> &'static str {
93        match self {
94            Self::SendMessage => Self::SEND_MESSAGE,
95            Self::GetMessages => Self::GET_MESSAGES,
96            Self::UploadFile => Self::UPLOAD_FILE,
97            Self::ResumableUploadFile => Self::RESUMABLE_UPLOAD_FILE,
98            Self::EditMessage => Self::EDIT_MESSAGE,
99            Self::DeleteMessage => Self::DELETE_MESSAGE,
100            Self::GetMessage => Self::GET_MESSAGE,
101            Self::GetMessageHistory => Self::GET_MESSAGE_HISTORY,
102            Self::ReportMessage => Self::REPORT_MESSAGE,
103            Self::MatchesNarrow => Self::MATCHES_NARROW,
104            Self::Register => Self::REGISTER,
105            Self::Reaction => Self::REACTION,
106            Self::Render => Self::RENDER,
107            Self::FetchApiKey => Self::FETCH_API_KEY,
108            Self::UpdateMessageFlags => Self::UPDATE_MESSAGE_FLAGS,
109            Self::UpdateMessageFlagsNarrow => Self::UPDATE_MESSAGE_FLAGS_NARROW,
110            Self::MarkAllAsRead => Self::MARK_ALL_AS_READ,
111            Self::MarkStreamAsRead => Self::MARK_STREAM_AS_READ,
112            Self::MarkTopicAsRead => Self::MARK_TOPIC_AS_READ,
113        }
114    }
115}
116
117impl From<Endpoint> for &'static str {
118    fn from(val: Endpoint) -> Self {
119        val.as_str()
120    }
121}
122
123impl From<Endpoint> for String {
124    fn from(val: Endpoint) -> Self {
125        val.as_str().to_string()
126    }
127}
128
129impl_default!(Endpoint);
130impl_display!(Endpoint: str);