pub mod series;
pub mod sources;
pub mod tags;
pub mod related_tags;
pub mod tables;
use serde::Deserialize;
use std::fmt::{self, Display, Formatter};
#[derive(Deserialize, Clone, Debug, Default)]
pub struct Response {
pub realtime_start: String,
pub realtime_end: String,
pub order_by: Option<String>,
pub sort_order: Option<String>,
pub count: Option<usize>,
pub offset: Option<usize>,
pub limit: Option<usize>,
pub releases: Vec<Release>,
}
impl Display for Response {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
for item in self.releases.iter() {
match item.fmt(f) {
Ok(_) => (),
Err(e) => return Err(e),
}
match writeln!(f, "") {
Ok(_) => (),
Err(e) => return Err(e),
}
}
Ok(())
}
}
#[derive(Deserialize, Clone, Debug, Default)]
pub struct Release {
pub id: usize,
pub realtime_start: String,
pub realtime_end: String,
pub name: String,
pub press_release: bool,
pub link: Option<String>,
pub notes: Option<String>
}
impl Display for Release {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "Release {}: {}", self.id, self.name)
}
}
pub struct Builder {
option_string: String
}
impl Builder {
pub fn new() -> Builder {
Builder {
option_string: String::new(),
}
}
pub(crate) fn build(self) -> String {
self.option_string
}
pub fn realtime_start(&mut self, start_date: &str) -> &mut Builder {
self.option_string += format!("&realtime_start={}", start_date).as_str();
self
}
pub fn realtime_end(&mut self, end_date: &str) -> &mut Builder {
self.option_string += format!("&realtime_end={}", end_date).as_str();
self
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::client::FredClient;
#[test]
fn release_with_options() {
let mut c = match FredClient::new() {
Ok(c) => c,
Err(msg) => {
println!("{}", msg);
assert_eq!(2, 1);
return
},
};
let mut builder = Builder::new();
builder.realtime_start("2000-01-01");
let resp: Response = match c.release(9, Some(builder)) {
Ok(resp) => resp,
Err(msg) => {
println!("{}", msg);
assert_eq!(2, 1);
return
},
};
for item in resp.releases {
println!("{}: {}", item.name, item.press_release);
}
}
}