bpi_rs/manga/
activity.rs

1//! 漫画任务操作
2//!
3//! https://github.com/SocialSisterYi/bilibili-API-collect/blob/master/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    /// 文档: https://github.com/SocialSisterYi/bilibili-API-collect/tree/master/docs/manga
24    pub async fn manga_share_comic(&self) -> Result<ShareComicResponse, BpiError> {
25        let params = [("platform", "android")];
26        self
27            .post("https://manga.bilibili.com/twirp/activity.v1.Activity/ShareComic")
28            .form(&params)
29            .send_bpi("分享漫画").await
30    }
31}
32
33#[cfg(test)]
34mod tests {
35    use super::*;
36
37    #[tokio::test]
38    async fn test_share_comic() -> Result<(), Box<BpiError>> {
39        let bpi = BpiClient::new();
40
41        let result = bpi.manga_share_comic().await?;
42
43        // 可能是成功获取积分,也可能是今日已分享
44
45        // 如果是成功获取积分,则data存在且point为5
46        let data = result.into_data()?;
47
48        assert_eq!(data.point, 5);
49
50        Ok(())
51    }
52}