1use serde::{ Deserialize, Serialize };
2
3use crate::{ BilibiliRequest, BpiClient, BpiError, BpiResponse };
4
5#[derive(Debug, Serialize, Clone, Deserialize)]
8pub struct PageInfo {
9 pub total_page: i32,
11 pub cur_page: i32,
13}
14
15#[derive(Debug, Serialize, Clone, Deserialize)]
16pub struct FansMedalItem {
17 #[serde(rename = "can_deleted")]
19 pub can_delete: bool,
20 pub day_limit: i32,
22 pub guard_level: i32,
24 pub guard_medal_title: String,
26 pub intimacy: i32,
28 pub is_lighted: i32,
30 pub level: i32,
32 pub medal_name: String,
34 pub medal_color_border: i32,
36 pub medal_color_start: i32,
38 pub medal_color_end: i32,
40 pub medal_id: i64,
42 pub next_intimacy: i32,
44 pub today_feed: i32,
46 pub roomid: i64,
48 pub status: i32,
50 pub target_id: i64,
52 pub target_name: String,
54 pub uname: String,
56}
57
58#[derive(Debug, Serialize, Clone, Deserialize)]
59pub struct MyMedalsData {
60 pub count: i32,
62 pub items: Vec<FansMedalItem>,
64 pub page_info: PageInfo,
66}
67
68pub type MyMedalsResponse = BpiResponse<MyMedalsData>;
69
70impl BpiClient {
73 pub async fn live_my_medals(
79 &self,
80 page: i32,
81 page_size: i32
82 ) -> Result<MyMedalsResponse, BpiError> {
83 let params = [
84 ("page", page.to_string()),
85 ("page_size", page_size.to_string()),
86 ];
87
88 let resp: MyMedalsResponse = self
89 .get("https://api.live.bilibili.com/xlive/app-ucenter/v1/user/GetMyMedals")
90 .query(¶ms)
91 .send_bpi("获取自己持有的粉丝勋章信息").await?;
92
93 Ok(resp)
94 }
95}
96
97#[cfg(test)]
98mod tests {
99 use super::*;
100
101 #[tokio::test]
102 async fn test_get_my_medals() -> Result<(), Box<BpiError>> {
103 let bpi = BpiClient::new();
104 let resp = bpi.live_my_medals(1, 10).await?;
105
106 tracing::info!("{:?}", resp.data);
107 Ok(())
108 }
109}