mod api;
mod model;
mod wire;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
pub enum NewsTab {
#[default]
News,
All,
PressReleases,
}
pub use model::NewsArticle;
use crate::{
YfClient, YfError,
core::client::{CacheMode, RetryConfig},
};
pub(crate) const fn tab_as_str(tab: NewsTab) -> &'static str {
match tab {
NewsTab::News => "latestNews",
NewsTab::All => "newsAll",
NewsTab::PressReleases => "pressRelease",
}
}
pub struct NewsBuilder {
client: YfClient,
symbol: String,
count: u32,
tab: NewsTab,
cache_mode: CacheMode,
retry_override: Option<RetryConfig>,
}
impl NewsBuilder {
pub fn new(client: &YfClient, symbol: impl Into<String>) -> Self {
Self {
client: client.clone(),
symbol: symbol.into(),
count: 10,
tab: NewsTab::default(),
cache_mode: CacheMode::Use,
retry_override: None,
}
}
#[must_use]
pub const fn cache_mode(mut self, mode: CacheMode) -> Self {
self.cache_mode = mode;
self
}
#[must_use]
pub fn retry_policy(mut self, cfg: Option<RetryConfig>) -> Self {
self.retry_override = cfg;
self
}
#[must_use]
pub const fn count(mut self, count: u32) -> Self {
self.count = count;
self
}
#[must_use]
pub const fn tab(mut self, tab: NewsTab) -> Self {
self.tab = tab;
self
}
pub async fn fetch(self) -> Result<Vec<NewsArticle>, YfError> {
api::fetch_news(
&self.client,
&self.symbol,
self.count,
self.tab,
self.cache_mode,
self.retry_override.as_ref(),
)
.await
}
}