Skip to main content

bpi_rs/creativecenter/
railgun.rs

1//! 电磁力等级 API
2//!
3//! [参考文档](https://github.com/SocialSisterYi/bilibili-API-collect/blob/master/docs/creativecenter/railgun.md)
4
5use crate::{ BilibiliRequest, BpiClient, BpiError, BpiResponse };
6use serde::{ Deserialize, Serialize };
7
8/// 电磁力等级信息
9#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct ElectromagneticInfo {
11    /// 当前用户 mid
12    pub mid: u64,
13    /// 电磁力等级
14    pub level: u32,
15    /// 电磁力分数
16    pub score: u32,
17    /// 信用分
18    pub credit: u32,
19    /// 状态 (文档不明,返回固定 2)
20    pub state: i32,
21}
22
23impl BpiClient {
24    /// 获取电磁力等级
25    ///
26    /// 获取当前用户的电磁力等级信息,包括等级、分数、信用分等。
27    ///
28    /// # 文档
29    /// [获取电磁力等级](https://github.com/SocialSisterYi/bilibili-API-collect/blob/master/docs/creativecenter/railgun.md#获取电磁力等级)
30    pub async fn up_electromagnetic_info(
31        &self
32    ) -> Result<BpiResponse<ElectromagneticInfo>, BpiError> {
33        self
34            .get("https://api.bilibili.com/studio/up-rating/v3/rating/info")
35            .send_bpi("获取电磁力等级").await
36    }
37}
38
39#[cfg(test)]
40mod tests {
41    use super::*;
42
43    #[tokio::test]
44    async fn test_electromagnetic_info() -> Result<(), Box<BpiError>> {
45        let bpi = BpiClient::new();
46
47        let data = bpi.up_electromagnetic_info().await?.into_data()?;
48
49        tracing::info!(
50            "mid={}, level={}, score={}, credit={}, state={}",
51            data.mid,
52            data.level,
53            data.score,
54            data.credit,
55            data.state
56        );
57
58        Ok(())
59    }
60}