Skip to main content

bpi_rs/manga/
activity.rs

1//! 漫画任务操作
2//!
3//! [查看 API 文档](https://github.com/Yuelioi/bilibili-API-collect/tree/cfc5fddcc8a94b74d91970bb5b4eaeb349addc47/docs/manga/Activity.md)
4
5use crate::{ BilibiliRequest, BpiClient, BpiError, BpiResponse };
6use serde::{ Deserialize, Serialize };
7
8// ================= 数据结构 =================
9
10#[derive(Debug, Serialize, Clone, Deserialize)]
11pub struct ShareComicData {
12    /// 获取积分
13    pub point: i32,
14}
15
16pub type ShareComicResponse = BpiResponse<ShareComicData>;
17
18// ================= 实现 =================
19
20impl BpiClient {
21    /// 分享漫画获取积分
22    ///
23    /// # 文档
24    /// [查看API文档](https://github.com/SocialSisterYi/bilibili-API-collect/tree/master/docs/manga)
25    pub async fn manga_share_comic(&self) -> Result<ShareComicResponse, BpiError> {
26        let params = [("platform", "android")];
27        self
28            .post("https://manga.bilibili.com/twirp/activity.v1.Activity/ShareComic")
29            .form(&params)
30            .send_bpi("分享漫画").await
31    }
32}
33
34#[cfg(test)]
35mod tests {
36    use super::*;
37
38    #[tokio::test]
39    async fn test_share_comic() -> Result<(), Box<BpiError>> {
40        let bpi = BpiClient::new();
41
42        let result = bpi.manga_share_comic().await?;
43
44        // 可能是成功获取积分,也可能是今日已分享
45
46        // 如果是成功获取积分,则data存在且point为5
47        let data = result.into_data()?;
48
49        assert_eq!(data.point, 5);
50
51        Ok(())
52    }
53}