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(
78 &self,
79 page: i32,
80 page_size: i32,
81 ) -> Result<MyMedalsResponse, BpiError> {
82 let params = [
83 ("page", page.to_string()),
84 ("page_size", page_size.to_string()),
85 ];
86
87 let resp: MyMedalsResponse = self
88 .get("https://api.live.bilibili.com/xlive/app-ucenter/v1/user/GetMyMedals")
89 .query(¶ms)
90 .send_bpi("获取自己持有的粉丝勋章信息")
91 .await?;
92
93 Ok(resp)
94 }
95}
96
97#[cfg(test)]
98mod tests {
99 use super::*;
100
101 #[tokio::test]
102
103 async fn test_get_my_medals() -> Result<(), Box<BpiError>> {
104 let bpi = BpiClient::new();
105 let resp = bpi.live_my_medals(1, 10).await?;
106
107 tracing::info!("{:?}", resp.data);
108 Ok(())
109 }
110}