use time::Date;
use crate::wsh::{AutoFill, WshEventData};
use crate::Error;
#[cfg(test)]
#[path = "builder_tests.rs"]
mod tests;
#[must_use = "WshEventDataBuilder does nothing until you call .fetch()"]
pub struct WshEventDataBuilder<'a, C> {
client: &'a C,
contract_id: i32,
start_date: Option<Date>,
end_date: Option<Date>,
limit: Option<i32>,
auto_fill: Option<AutoFill>,
}
impl<'a, C> WshEventDataBuilder<'a, C> {
pub(crate) fn new(client: &'a C, contract_id: i32) -> Self {
Self {
client,
contract_id,
start_date: None,
end_date: None,
limit: None,
auto_fill: None,
}
}
pub fn starting(mut self, start_date: Date) -> Self {
self.start_date = Some(start_date);
self
}
pub fn ending(mut self, end_date: Date) -> Self {
self.end_date = Some(end_date);
self
}
pub fn limit(mut self, limit: i32) -> Self {
self.limit = Some(limit);
self
}
pub fn auto_fill(mut self, auto_fill: AutoFill) -> Self {
self.auto_fill = Some(auto_fill);
self
}
}
#[must_use = "WshEventFilterBuilder does nothing until you call .subscribe()"]
pub struct WshEventFilterBuilder<'a, C> {
client: &'a C,
filter: &'a str,
limit: Option<i32>,
auto_fill: Option<AutoFill>,
}
impl<'a, C> WshEventFilterBuilder<'a, C> {
pub(crate) fn new(client: &'a C, filter: &'a str) -> Self {
Self {
client,
filter,
limit: None,
auto_fill: None,
}
}
pub fn limit(mut self, limit: i32) -> Self {
self.limit = Some(limit);
self
}
pub fn auto_fill(mut self, auto_fill: AutoFill) -> Self {
self.auto_fill = Some(auto_fill);
self
}
}
#[cfg(feature = "sync")]
impl<'a> WshEventDataBuilder<'a, crate::client::sync::Client> {
pub fn fetch(self) -> Result<WshEventData, Error> {
crate::wsh::sync::wsh_event_data_by_contract(self.client, self.contract_id, self.start_date, self.end_date, self.limit, self.auto_fill)
}
}
#[cfg(feature = "sync")]
impl<'a> WshEventFilterBuilder<'a, crate::client::sync::Client> {
pub fn subscribe(self) -> Result<crate::subscriptions::sync::Subscription<WshEventData>, Error> {
crate::wsh::sync::wsh_event_data_by_filter(self.client, self.filter, self.limit, self.auto_fill)
}
}
#[cfg(feature = "async")]
impl<'a> WshEventDataBuilder<'a, crate::client::r#async::Client> {
pub async fn fetch(self) -> Result<WshEventData, Error> {
crate::wsh::r#async::wsh_event_data_by_contract(self.client, self.contract_id, self.start_date, self.end_date, self.limit, self.auto_fill)
.await
}
}
#[cfg(feature = "async")]
impl<'a> WshEventFilterBuilder<'a, crate::client::r#async::Client> {
pub async fn subscribe(self) -> Result<crate::subscriptions::r#async::Subscription<WshEventData>, Error> {
crate::wsh::r#async::wsh_event_data_by_filter(self.client, self.filter, self.limit, self.auto_fill).await
}
}