pub mod categories;
pub mod observation;
pub mod release;
pub mod tags;
pub mod search;
pub mod updates;
pub mod vintagedates;
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 seriess: Vec<Series>,
}
impl Display for Response {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
for item in self.seriess.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 Series {
pub id: String,
pub realtime_start: String,
pub realtime_end: String,
pub title: String,
pub observation_start: String,
pub observation_end: String,
pub frequency: String,
pub frequency_short: String,
pub units: String,
pub units_short: String,
pub seasonal_adjustment: String,
pub seasonal_adjustment_short: String,
pub last_updated: String,
pub popularity: isize,
pub group_popularity: Option<isize>,
pub notes: Option<String>,
}
impl Display for Series {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "Series {}: {}", self.id, self.title)
}
}
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 series_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.series("UNRATE", Some(builder)) {
Ok(resp) => resp,
Err(msg) => {
println!("{}", msg);
assert_eq!(2, 1);
return
},
};
for item in resp.seriess {
println!("{}: {} {} {}", item.id, item.title, item.realtime_start, item.realtime_end);
}
}
}