financial_api/fund/
news.rs1use crate::endpoints;
2use crate::{Client, Cursor, Error, FundNewsData, FundType, Response, Thscode, ValidationError};
3
4use super::FundTarget;
5
6impl Client {
7 pub async fn fund_news_article_list(
9 &self,
10 fund_type: FundType,
11 thscode: &Thscode,
12 limit: Option<u32>,
13 offset: Option<&Cursor>,
14 ) -> Result<Response<FundNewsData>, Error> {
15 let target = FundTarget::new(fund_type, thscode)?;
16 if limit == Some(0) {
17 return Err(ValidationError::new("limit", "must be at least 1").into());
18 }
19 let mut query = target.query();
20 if let Some(limit) = limit {
21 query.push(("limit", limit.to_string()));
22 }
23 if let Some(offset) = offset {
24 query.push(("offset", offset.to_string()));
25 }
26 self.get(endpoints::FUND_NEWS, &query).await
27 }
28}
29
30#[cfg(test)]
31mod tests {
32 use super::*;
33 use crate::ApiKey;
34
35 #[tokio::test]
36 async fn article_limit_must_be_positive() {
37 let client = Client::builder(ApiKey::new("test-api-key").unwrap())
38 .base_url("http://127.0.0.1:9")
39 .build()
40 .unwrap();
41 let fund = Thscode::new("025480.OF").unwrap();
42
43 let error = client
44 .fund_news_article_list(FundType::Otc, &fund, Some(0), None)
45 .await
46 .unwrap_err();
47
48 assert!(matches!(error, Error::InvalidInput(_)));
49 }
50}