bpi_rs/web_widget/
zone_upload.rs1use serde::Deserialize;
2use std::collections::HashMap;
3
4use crate::{ BilibiliRequest, BpiClient, BpiError, BpiResponse };
5
6#[derive(Debug, Clone, Deserialize)]
9pub struct OnlineRegionCount(pub HashMap<String, u64>);
10
11#[derive(Debug, Clone, Deserialize)]
13pub struct OnlineData {
14 pub region_count: OnlineRegionCount,
15}
16
17impl BpiClient {
18 pub async fn web_widget_online(&self) -> Result<BpiResponse<OnlineData>, BpiError> {
21 self
22 .get("https://api.bilibili.com/x/web-interface/online")
23 .send_bpi("获取分区当日投稿数").await
24 }
25}
26
27#[cfg(test)]
28mod tests {
29 use super::*;
30 use tracing::info;
31
32 #[tokio::test]
33 async fn test_get_online() {
34 let bpi = BpiClient::new();
35 let resp = bpi.web_widget_online().await;
36 info!("响应: {:?}", resp);
37 assert!(resp.is_ok());
38
39 if let Ok(data) = resp {
40 if let Some(counts) = data.data {
41 for (region_id, count) in counts.region_count.0 {
42 info!("分区ID: {}, 投稿数: {}", region_id, count);
43 }
44 }
45 }
46 }
47}