mod api;
mod model;
mod wire;
use serde::{Deserialize, Serialize};
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
pub enum NewsTab {
#[default]
News,
All,
PressReleases,
}
pub use model::NewsArticle;
use crate::{YfClient, YfError, YfResponse, core::CallOptions};
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,
options: CallOptions,
}
impl NewsBuilder {
pub fn new(client: &YfClient, symbol: impl Into<String>) -> Self {
Self {
client: client.clone(),
symbol: symbol.into(),
count: 10,
tab: NewsTab::default(),
options: CallOptions::default(),
}
}
crate::core::impl_call_option_setters!();
#[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> {
Ok(self.fetch_with_diagnostics().await?.into_data())
}
pub async fn fetch_with_diagnostics(&self) -> Result<YfResponse<Vec<NewsArticle>>, YfError> {
api::fetch_news(
&self.client,
&self.symbol,
self.count,
self.tab,
&self.options,
)
.await
}
}