torbox_notifications_rs/
lib.rs1use torbox_core_rs::{
2 api::ApiResponse,
3 client::{Endpoint, TorboxClient},
4 data::notifications::NotificationFeed,
5 error::ApiError,
6 network::constants::CONTENT_XML,
7};
8
9use crate::{
10 endpoint::{
11 ClearAllNotificationsEp, ClearSingleNotificationEp, GetNotifFeedEp, GetRssNotifFeedEp,
12 SendTestNotificationEp,
13 },
14 query::{ClearSingleNotificationQuery, RssFeedQuery},
15};
16
17pub mod endpoint;
18pub mod query;
19pub mod tests;
20pub mod types;
21
22#[cfg_attr(feature = "specta", derive(specta::Type))]
29pub struct NotificationApi<'a> {
30 client: &'a TorboxClient,
31}
32
33impl<'a> NotificationApi<'a> {
34 pub fn new(client: &'a TorboxClient) -> Self {
35 Self { client }
36 }
37
38 pub async fn get_rss_feed(&self) -> Result<String, ApiError> {
39 Endpoint::<GetRssNotifFeedEp>::new(self.client)
40 .call_query_raw(
41 RssFeedQuery {
42 token: self.client.token().to_string(),
43 },
44 CONTENT_XML,
45 )
46 .await
47 }
48
49 pub async fn get_feed(&self) -> Result<ApiResponse<Vec<NotificationFeed>>, ApiError> {
50 Endpoint::<GetNotifFeedEp>::new(self.client)
51 .call_query(())
52 .await
53 }
54
55 pub async fn clear(&self, id: u64) -> Result<ApiResponse<()>, ApiError> {
56 Endpoint::<ClearSingleNotificationEp>::new(self.client)
57 .call_query(ClearSingleNotificationQuery { id })
58 .await
59 }
60
61 pub async fn clear_all(&self) -> Result<ApiResponse<()>, ApiError> {
62 Endpoint::<ClearAllNotificationsEp>::new(self.client)
63 .call_query(())
64 .await
65 }
66
67 pub async fn send_test(&self) -> Result<ApiResponse<()>, ApiError> {
68 Endpoint::<SendTestNotificationEp>::new(self.client)
69 .call_query(())
70 .await
71 }
72}