use crate::{BilibiliRequest, BpiClient, BpiError, BpiResponse};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct DynamicBannerData {
pub banners: Vec<DynamicBanner>,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct DynamicBanner {
pub banner_id: u64,
pub end_time: u64,
pub img_url: String,
pub link: String,
pub platform: u64,
pub position: String,
pub start_time: u64,
pub title: String,
pub weight: u64,
}
impl BpiClient {
pub async fn dynamic_feed_banner(&self) -> Result<BpiResponse<DynamicBannerData>, BpiError> {
let req = self
.get("https://api.bilibili.com/x/dynamic/feed/dyn/banner")
.query(&[
("platform", "1"),
("position", "web动态"),
("web_location", "333.1365"),
]);
req.send_bpi("获取动态首页公告栏").await
}
}
#[cfg(test)]
mod tests {
use super::*;
use tracing::info;
#[tokio::test]
async fn test_dynamic_feed_banner() -> Result<(), BpiError> {
let bpi = BpiClient::new();
let resp = bpi.dynamic_feed_banner().await?;
let data = resp.into_data()?;
info!("成功获取到 {} 条公告", data.banners.len());
assert!(!data.banners.is_empty());
Ok(())
}
}