rbx_api/notifications/
mod.rs1pub mod models;
2
3use serde_json::json;
4
5use crate::{
6 errors::RobloxApiResult,
7 helpers::{handle, handle_as_json},
8 models::AssetId,
9 RobloxApi,
10};
11
12use self::models::{
13 CreateNotificationResponse, ListNotificationResponse, ListNotificationsResponse,
14};
15
16impl RobloxApi {
17 pub async fn create_notification(
18 &self,
19 experience_id: AssetId,
20 name: String,
21 content: String,
22 ) -> RobloxApiResult<CreateNotificationResponse> {
23 let req = self
24 .client
25 .post("https://apis.roblox.com/notifications/v1/developer-configuration/create-notification")
26 .json(&json!({
27 "universeId": experience_id,
28 "name": name,
29 "content": content,
30 }));
31
32 handle_as_json(req).await
33 }
34
35 pub async fn update_notification(
36 &self,
37 notification_id: String,
38 name: String,
39 content: String,
40 ) -> RobloxApiResult<()> {
41 let req = self
42 .client
43 .post("https://apis.roblox.com/notifications/v1/developer-configuration/update-notification")
44 .json(&json!({
45 "id": notification_id,
46 "name": name,
47 "content": content,
48 }));
49
50 handle(req).await?;
51
52 Ok(())
53 }
54
55 pub async fn archive_notification(&self, notification_id: String) -> RobloxApiResult<()> {
56 let req = self
57 .client
58 .post("https://apis.roblox.com/notifications/v1/developer-configuration/archive-notification")
59 .json(&json!({
60 "id": notification_id,
61 }));
62
63 handle(req).await?;
64
65 Ok(())
66 }
67
68 pub async fn list_notifications(
69 &self,
70 experience_id: AssetId,
71 count: u8,
72 page_cursor: Option<String>,
73 ) -> RobloxApiResult<ListNotificationsResponse> {
74 let mut req = self
75 .client
76 .get("https://apis.roblox.com/notifications/v1/developer-configuration/experience-notifications-list")
77 .query(&[
78 ("universeId", &experience_id.to_string()),
79 ("count", &count.to_string()),
80 ]);
81 if let Some(page_cursor) = page_cursor {
82 req = req.query(&[("cursor", &page_cursor)]);
83 }
84
85 handle_as_json(req).await
86 }
87
88 pub async fn get_all_notifications(
89 &self,
90 experience_id: AssetId,
91 ) -> RobloxApiResult<Vec<ListNotificationResponse>> {
92 let mut all_notifications = Vec::new();
93
94 let mut page_cursor: Option<String> = None;
95 loop {
96 let res = self
97 .list_notifications(experience_id, 100, page_cursor)
98 .await?;
99 all_notifications.extend(res.notification_string_configs);
100
101 match res.next_page_cursor {
102 None => break,
103 Some(next_page_cursor) if next_page_cursor.is_empty() => break,
104 _ => {}
105 }
106
107 page_cursor = res.next_page_cursor;
108 }
109
110 Ok(all_notifications)
111 }
112}