Skip to main content

uptrakit_openapi_client/
notifications.rs

1use crate::types_impl::notifications::{
2    CreateNotificationChannelRequest, CreateNotificationRuleRequest, NotificationChannelResponse,
3    NotificationLogResponse, NotificationRuleResponse, TestNotificationResponse,
4    UpdateNotificationChannelRequest, UpdateNotificationRuleRequest,
5};
6use crate::types_impl::pagination::{PaginatedResponse, PaginationParams};
7use uuid::Uuid;
8
9use crate::Result;
10use crate::paths;
11
12impl crate::UptrakitClient {
13    // ── Channels ────────────────────────────────────────────────────
14
15    /// Create a new notification channel.
16    pub async fn create_notification_channel(
17        &self,
18        req: &CreateNotificationChannelRequest,
19    ) -> Result<NotificationChannelResponse> {
20        self.post_json(paths::notifications::CHANNELS, req).await
21    }
22
23    /// List notification channels with pagination.
24    pub async fn list_notification_channels(
25        &self,
26        params: &PaginationParams,
27    ) -> Result<PaginatedResponse<NotificationChannelResponse>> {
28        self.get_with_query(paths::notifications::CHANNELS, params)
29            .await
30    }
31
32    /// Get a single notification channel by ID.
33    pub async fn get_notification_channel(&self, id: &Uuid) -> Result<NotificationChannelResponse> {
34        self.get(&paths::notifications::channel_by_id(id)).await
35    }
36
37    /// Update an existing notification channel.
38    pub async fn update_notification_channel(
39        &self,
40        id: &Uuid,
41        req: &UpdateNotificationChannelRequest,
42    ) -> Result<NotificationChannelResponse> {
43        self.put_json(&paths::notifications::channel_by_id(id), req)
44            .await
45    }
46
47    /// Delete a notification channel.
48    pub async fn delete_notification_channel(&self, id: &Uuid) -> Result<()> {
49        self.delete(&paths::notifications::channel_by_id(id)).await
50    }
51
52    /// Send a test notification through a channel.
53    pub async fn test_notification_channel(&self, id: &Uuid) -> Result<TestNotificationResponse> {
54        self.post_empty(&paths::notifications::test_channel(id))
55            .await
56    }
57
58    // ── Rules ───────────────────────────────────────────────────────
59
60    /// Create a new notification rule.
61    pub async fn create_notification_rule(
62        &self,
63        req: &CreateNotificationRuleRequest,
64    ) -> Result<NotificationRuleResponse> {
65        self.post_json(paths::notifications::RULES, req).await
66    }
67
68    /// List notification rules with pagination.
69    pub async fn list_notification_rules(
70        &self,
71        params: &PaginationParams,
72    ) -> Result<PaginatedResponse<NotificationRuleResponse>> {
73        self.get_with_query(paths::notifications::RULES, params)
74            .await
75    }
76
77    /// Get a single notification rule by ID.
78    pub async fn get_notification_rule(&self, id: &Uuid) -> Result<NotificationRuleResponse> {
79        self.get(&paths::notifications::rule_by_id(id)).await
80    }
81
82    /// Update an existing notification rule.
83    pub async fn update_notification_rule(
84        &self,
85        id: &Uuid,
86        req: &UpdateNotificationRuleRequest,
87    ) -> Result<NotificationRuleResponse> {
88        self.put_json(&paths::notifications::rule_by_id(id), req)
89            .await
90    }
91
92    /// Delete a notification rule.
93    pub async fn delete_notification_rule(&self, id: &Uuid) -> Result<()> {
94        self.delete(&paths::notifications::rule_by_id(id)).await
95    }
96
97    // ── Log ─────────────────────────────────────────────────────────
98
99    /// List the notification log with pagination.
100    pub async fn list_notification_log(
101        &self,
102        params: &PaginationParams,
103    ) -> Result<PaginatedResponse<NotificationLogResponse>> {
104        self.get_with_query(paths::notifications::LOG, params).await
105    }
106}