speedrun_api/api/
notifications.rs

1//! # Notifications
2//!
3//! Endpoints available for notifications.
4
5use serde::Serialize;
6
7use super::{endpoint::Endpoint, error::BodyError, query_params::QueryParams, Direction};
8
9/// Sorting options for notifications
10#[derive(Debug, Clone, Serialize, Copy)]
11pub enum NotificationsSorting {
12    /// Sort by the date the notification was created (default)
13    Created,
14}
15
16/// Retrieves the notifications for the currently authenticated user.
17#[derive(Default, Debug, Builder, Clone, Serialize)]
18#[builder(default, setter(into, strip_option))]
19#[serde(rename_all = "kebab-case")]
20pub struct Notifications {
21    #[doc = r"Sorting options for results (default: Sorted by date)."]
22    orderby: Option<NotificationsSorting>,
23    #[doc = r"Sort direction. (default: descending)"]
24    direction: Option<Direction>,
25}
26
27impl Notifications {
28    /// Create a builder for this endpoint.
29    pub fn builder() -> NotificationsBuilder {
30        NotificationsBuilder::default()
31    }
32}
33
34impl Default for NotificationsSorting {
35    fn default() -> Self {
36        Self::Created
37    }
38}
39
40impl Endpoint for Notifications {
41    fn endpoint(&self) -> std::borrow::Cow<'static, str> {
42        "notifications".into()
43    }
44
45    fn query_parameters(&self) -> Result<QueryParams<'_>, BodyError> {
46        QueryParams::with(self)
47    }
48
49    fn requires_authentication(&self) -> bool {
50        true
51    }
52}