-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rbx_mantle,rbx_api): add notification string support (#187)
* feat(rbx_mantle,rbx_api): add notification string support * Add notifications to state * changed notifications to a HashMap and fixed other issues * fix: linting errors * fix: wrong line ending * improve naming * fix naming * add docs * improve docs language --------- Co-authored-by: Kevin <[email protected]>
- Loading branch information
1 parent
273cdf0
commit 955b3df
Showing
6 changed files
with
239 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
pub mod models; | ||
|
||
use serde_json::json; | ||
|
||
use crate::{ | ||
errors::RobloxApiResult, | ||
helpers::{handle, handle_as_json}, | ||
models::AssetId, | ||
RobloxApi, | ||
}; | ||
|
||
use self::models::{ | ||
CreateNotificationResponse, ListNotificationResponse, ListNotificationsResponse, | ||
}; | ||
|
||
impl RobloxApi { | ||
pub async fn create_notification( | ||
&self, | ||
experience_id: AssetId, | ||
name: String, | ||
content: String, | ||
) -> RobloxApiResult<CreateNotificationResponse> { | ||
let req = self | ||
.client | ||
.post("https://apis.roblox.com/notifications/v1/developer-configuration/create-notification") | ||
.json(&json!({ | ||
"universeId": experience_id, | ||
"name": name, | ||
"content": content, | ||
})); | ||
|
||
handle_as_json(req).await | ||
} | ||
|
||
pub async fn update_notification( | ||
&self, | ||
notification_id: String, | ||
name: String, | ||
content: String, | ||
) -> RobloxApiResult<()> { | ||
let req = self | ||
.client | ||
.post("https://apis.roblox.com/notifications/v1/developer-configuration/update-notification") | ||
.json(&json!({ | ||
"id": notification_id, | ||
"name": name, | ||
"content": content, | ||
})); | ||
|
||
handle(req).await?; | ||
|
||
Ok(()) | ||
} | ||
|
||
pub async fn archive_notification(&self, notification_id: String) -> RobloxApiResult<()> { | ||
let req = self | ||
.client | ||
.post("https://apis.roblox.com/notifications/v1/developer-configuration/archive-notification") | ||
.json(&json!({ | ||
"id": notification_id, | ||
})); | ||
|
||
handle(req).await?; | ||
|
||
Ok(()) | ||
} | ||
|
||
pub async fn list_notifications( | ||
&self, | ||
experience_id: AssetId, | ||
count: u8, | ||
page_cursor: Option<String>, | ||
) -> RobloxApiResult<ListNotificationsResponse> { | ||
let mut req = self | ||
.client | ||
.get("https://apis.roblox.com/notifications/v1/developer-configuration/experience-notifications-list") | ||
.query(&[ | ||
("universeId", &experience_id.to_string()), | ||
("count", &count.to_string()), | ||
]); | ||
if let Some(page_cursor) = page_cursor { | ||
req = req.query(&[("cursor", &page_cursor)]); | ||
} | ||
|
||
handle_as_json(req).await | ||
} | ||
|
||
pub async fn get_all_notifications( | ||
&self, | ||
experience_id: AssetId, | ||
) -> RobloxApiResult<Vec<ListNotificationResponse>> { | ||
let mut all_notifications = Vec::new(); | ||
|
||
let mut page_cursor: Option<String> = None; | ||
loop { | ||
let res = self | ||
.list_notifications(experience_id, 100, page_cursor) | ||
.await?; | ||
all_notifications.extend(res.notification_string_configs); | ||
|
||
if res.next_page_cursor.is_none() { | ||
break; | ||
} | ||
|
||
page_cursor = res.next_page_cursor; | ||
} | ||
|
||
Ok(all_notifications) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use serde::Deserialize; | ||
|
||
#[derive(Deserialize, Clone)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct CreateNotificationResponse { | ||
pub id: String, | ||
} | ||
|
||
#[derive(Deserialize, Clone)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct ListNotificationsResponse { | ||
pub notification_string_configs: Vec<ListNotificationResponse>, | ||
pub previous_page_cursor: Option<String>, | ||
pub next_page_cursor: Option<String>, | ||
} | ||
|
||
#[derive(Deserialize, Clone)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct ListNotificationResponse { | ||
pub id: String, | ||
pub name: String, | ||
pub content: String, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
955b3df
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
mantle-docs – ./
mantle-docs-git-main-blake-pro.vercel.app
mantledeploy.vercel.app
mantle-docs.vercel.app
mantle-docs-blake-pro.vercel.app