Skip to main content

bpi_rs/live/
live_bill.rs

1use serde::{ Deserialize, Serialize };
2
3use crate::{ BilibiliRequest, BpiClient, BpiError, BpiResponse };
4
5// ================= 数据结构 =================
6
7#[derive(Debug, Serialize, Clone, Deserialize)]
8pub struct GiftTypeItem {
9    /// 礼物id
10    pub gift_id: i64,
11    /// 礼物名称
12    pub gift_name: String,
13    /// 瓜子数量(电池礼物为金瓜子数量,银瓜子礼物为银瓜子数量)
14    #[serde(default)]
15    pub price: i64,
16}
17
18impl BpiClient {
19    /// 获取所有礼物列表
20    ///
21    /// # 文档
22    /// [查看API文档](https://github.com/SocialSisterYi/bilibili-API-collect/tree/master/docs/live)
23    pub async fn live_gift_types(&self) -> Result<BpiResponse<Vec<GiftTypeItem>>, BpiError> {
24        let resp = self
25            .get("https://api.live.bilibili.com/gift/v1/master/getGiftTypes")
26            .send_bpi("获取所有礼物列表").await?;
27
28        Ok(resp)
29    }
30}
31
32#[cfg(test)]
33mod tests {
34    use super::*;
35
36    #[tokio::test]
37    async fn test_get_gift_types() -> Result<(), Box<BpiError>> {
38        let bpi = BpiClient::new();
39        let resp = bpi.live_gift_types().await?;
40
41        assert_eq!(resp.code, 0);
42        Ok(())
43    }
44}