//! Javascript-like loosely typed data-structures based on FRED API.
use std::fmt;
use serde::{Deserialize};
#[derive(Debug, Deserialize)]
pub struct Categories {
pub categories: Vec<Category>,
}
/// See [Fred docs: /fred/category](https://fred.stlouisfed.org/docs/api/fred/category.html).
///
#[derive(Debug, Deserialize)]
pub struct Category {
pub id: usize,
pub name: String,
pub parent_id: usize,
pub notes: Option<String>,
}
/// See [Fred docs: /fred/category/children](https://fred.stlouisfed.org/docs/api/fred/category_children.html).
#[derive(Debug, Deserialize)]
pub struct CategoryChildren {
pub categories: Vec<Category>,
}
/// See [Fred docs: /fred/category/related](https://fred.stlouisfed.org/docs/api/fred/category_related.html).
#[derive(Debug, Deserialize)]
pub struct CategoryRelated {
categories: Vec<Category>,
}
/// See Fred docs
#[derive(Debug, Deserialize)]
pub struct CategorySeries {
pub realtime_start: String,
pub realtime_end: String,
pub order_by: String,
pub count: isize,
pub offset: isize,
pub limit: isize,
pub seriess: Vec<SeriesItem>,
}
/// See [Fred docs: /fred/category/tags](https://fred.stlouisfed.org/docs/api/fred/category_tags.html).
#[derive(Debug, Deserialize)]
pub struct CategoryTags {
pub realtime_start: String,
pub realtime_end: String,
pub order_by: String,
pub sort_order: String,
pub count: isize,
pub offset: isize,
pub limit: isize,
pub tags: Vec<Tag>,
}
#[derive(Debug, Deserialize)]
pub struct Tag {
pub name: String,
pub group_id: String,
pub notes: Option<String>,
pub created: String,
pub popularity: isize,
pub series_count: isize,
}
impl fmt::Display for Tag {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f,
"name: {}\nnotes: {:?}\nseries_count: {}",
self.name,
self.notes,
self.series_count
)
}
}
/// See [Fred docs: /fred/category/related_tags](https://fred.stlouisfed.org/docs/api/fred/category_related_tags.html).
#[derive(Debug, Deserialize)]
pub struct CategoryRelatedTags {
pub realtime_start: String,
pub realtime_end: String,
pub order_by: String,
pub sort_order: String,
pub count: isize,
pub offset: isize,
pub limit: isize,
pub tags: Vec<Tag>,
}
/// See [Fred docs: /fred/releases](https://fred.stlouisfed.org/docs/api/fred/releases.html).
#[derive(Debug, Deserialize)]
pub struct Releases {
pub realtime_start: String,
pub realtime_end: String,
pub order_by: String,
pub sort_order: String,
pub count: isize,
pub offset: isize,
pub limit: isize,
pub releases: Vec<ReleaseItem>,
}
/// See [Fred docs: /fred/release](https://fred.stlouisfed.org/docs/api/fred/release.html).
#[derive(Debug, Deserialize)]
pub struct Release {
pub realtime_start: String,
pub realtime_end: String,
pub releases: Vec<ReleaseItem>,
}
#[derive(Debug, Deserialize)]
pub struct ReleaseItem {
pub id: isize,
pub realtime_start: String,
pub realtime_end: String,
pub name: String,
pub press_release: bool,
pub link: Option<String>,
}
/// See [Fred docs: /fred/release/dates](https://fred.stlouisfed.org/docs/api/fred/release_dates.html).
#[derive(Debug, Deserialize)]
pub struct ReleasesDates {
pub realtime_start: String,
pub realtime_end: String,
pub order_by: String,
pub sort_order: String,
pub count: isize,
pub offset: isize,
pub limit: isize,
pub release_dates: Vec<ReleaseDate>,
}
#[derive(Debug, Deserialize)]
pub struct ReleaseDates {
pub realtime_start: String,
pub realtime_end: String,
pub order_by: String,
pub sort_order: String,
pub count: isize,
pub offset: isize,
pub limit: isize,
pub release_dates: Vec<ReleaseDateItem>,
}
#[derive(Debug, Deserialize)]
pub struct ReleaseDateItem {
pub release_id: isize,
pub date: String,
}
#[derive(Debug, Deserialize)]
pub struct ReleaseDate {
pub release_id: isize,
pub release_name: String,
pub date: String,
}
/// See [Fred docs: /fred/release/series](https://fred.stlouisfed.org/docs/api/fred/release_series.html).
#[derive(Debug, Deserialize)]
pub struct ReleaseSeries {
pub realtime_start: String,
pub realtime_end: String,
pub order_by: String,
pub sort_order: String,
pub count: isize,
pub offset: isize,
pub limit: isize,
pub seriess: Vec<SeriesItem>,
}
/// See [Fred docs: /fred/release/sources](https://fred.stlouisfed.org/docs/api/fred/release_sources.html).
#[derive(Debug, Deserialize)]
pub struct ReleaseSources {
pub realtime_start: String,
pub realtime_end: String,
pub sources: Vec<SourceItem>,
}
#[derive(Debug, Deserialize)]
pub struct SourceItem {
pub id: isize,
pub realtime_start: String,
pub realtime_end: String,
pub name: String,
pub link: Option<String>,
}
/// See [Fred docs: /fred/release/tags](https://fred.stlouisfed.org/docs/api/fred/release_tags.html).
#[derive(Debug, Deserialize)]
pub struct ReleaseTags {
pub realtime_start: String,
pub realtime_end: String,
pub order_by: String,
pub sort_order: String,
pub count: isize,
pub offset: isize,
pub limit: isize,
pub tags: Vec<TagItem>,
}
#[derive(Debug, Deserialize)]
pub struct TagItem {
pub name: String,
pub group_id: String,
pub notes: Option<String>,
pub created: String,
pub popularity: isize,
pub series_count: isize,
}
/// See [Fred docs: /fred/release/related_tags](https://fred.stlouisfed.org/docs/api/fred/release_related_tags.html).
#[derive(Debug, Deserialize)]
pub struct ReleaseRelatedTags {
pub realtime_start: String,
pub realtime_end: String,
pub order_by: String,
pub sort_order: String,
pub count: isize,
pub offset: isize,
pub limit: isize,
pub tags: Vec<TagItem>,
}
/// See [Fred docs: /fred/release/related_tags](https://fred.stlouisfed.org/docs/api/fred/release_related_tags.html).
#[derive(Debug, Deserialize)]
pub struct ReleaseTables {
pub name: String,
pub element_id: isize,
pub release_id: String,
pub elements: Vec<ReleaseKeyVal>,
}
/// See [Fred docs: /fred/release/related_tags](https://fred.stlouisfed.org/docs/api/fred/release_related_tags.html).
#[derive(Debug, Deserialize)]
pub struct ReleaseKeyVal {
pub key: isize,
pub value: ReleaseElement,
}
/// See [Fred docs: /fred/release/related_tags](https://fred.stlouisfed.org/docs/api/fred/release_related_tags.html).
#[derive(Debug, Deserialize)]
pub struct ReleaseElement {
pub element_id: isize,
pub release_id: String,
pub series_id: String,
pub parent_id: String,
pub line: String,
#[serde(rename = "type")]
pub ty: String,
pub name: String,
pub level: String,
pub children: Vec<ReleaseElement>,
}
#[derive(Debug, Deserialize)]
pub struct Series {
pub realtime_start: String,
pub realtime_end: String,
pub seriess: Vec<SeriesItem>,
}
impl fmt::Display for Series {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut s = format!(
"{}-{}\n",
self.realtime_start,
self.realtime_end,
);
for item in &self.seriess {
s.push_str(&item.to_string())
};
write!(f, "{}", s)
}
}
#[derive(Debug, Deserialize)]
pub struct SeriesItem {
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 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 fmt::Display for SeriesItem {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(
f,
"{}\n{}\n{}-{}\n{}\n{}",
self.id,
self.title,
self.observation_start,
self.observation_end,
self.frequency,
self.seasonal_adjustment,
)
}
}
/// See [Fred docs: /fred/series/categories](https://fred.stlouisfed.org/docs/api/fred/series_categories.html).
#[derive(Debug, Deserialize)]
pub struct SeriesCategories {
pub categories: Vec<CategoryItem>,
}
#[derive(Debug, Deserialize)]
pub struct CategoryItem {
pub id: String,
pub name: String,
pub parent_id: isize,
}
/// See [Fred docs: /fred/series/observations](https://fred.stlouisfed.org/docs/api/fred/series_observations.html).
#[derive(Debug, Deserialize)]
pub struct SeriesObservations {
pub realtime_start: String,
pub realtime_end: String,
pub observation_start: String,
pub observation_end: String,
pub units: String,
pub output_type: isize,
pub file_type: String,
pub order_by: String,
pub sort_order: String,
pub count: isize,
pub offset: isize,
pub limit: isize,
pub observations: Vec<Observation>,
}
/// See [Fred docs: /fred/series/observations](https://fred.stlouisfed.org/docs/api/fred/series_observations.html).
#[derive(Debug, Deserialize)]
pub struct Observation {
pub realtime_start: String,
pub realtime_end: String,
pub date: String,
pub value: String,
}
/// See [Fred docs: /fred/series/release](https://fred.stlouisfed.org/docs/api/fred/series_release.html).
#[derive(Debug, Deserialize)]
pub struct SeriesRelease {
pub realtime_start: String,
pub realtime_end: String,
pub releases: Vec<ReleaseItem>,
}
/// See [Fred docs: /fred/series/search](https://fred.stlouisfed.org/docs/api/fred/series_search.html).
#[derive(Debug, Deserialize)]
pub struct SeriesSearch {
pub realtime_start: String,
pub realtime_end: String,
pub order_by: String,
pub sort_order: String,
pub count: isize,
pub offset: isize,
pub limit: isize,
pub seriess: Vec<SeriesItem>,
}
#[derive(Debug, Deserialize)]
pub struct SeriesSearchTags {
pub realtime_start: String,
pub realtime_end: String,
pub order_by: String,
pub sort_order: String,
pub count: isize,
pub offset: isize,
pub limit: isize,
pub tags: Vec<TagItem>,
}
/// See [Fred docs: /fred/series/search/related_tags](https://fred.stlouisfed.org/docs/api/fred/series_search_related_tags.html).
#[derive(Debug, Deserialize)]
pub struct SeriesSearchRelatedTags {
pub realtime_start: String,
pub realtime_end: String,
pub order_by: String,
pub sort_order: String,
pub count: isize,
pub offset: isize,
pub limit: isize,
pub tags: Vec<TagItem>,
}
/// See [Fred docs: /fred/series/tags](https://fred.stlouisfed.org/docs/api/fred/series_tags.html).
#[derive(Debug, Deserialize)]
pub struct SeriesTags {
pub realtime_start: String,
pub realtime_end: String,
pub order_by: String,
pub sort_order: String,
pub count: isize,
pub offset: isize,
pub limit: isize,
pub tags: Vec<TagItem>,
}
/// See [Fred docs: /fred/series/updates](https://fred.stlouisfed.org/docs/api/fred/series_updates.html).
#[derive(Debug, Deserialize)]
pub struct SeriesUpdates {
pub realtime_start: String,
pub realtime_end: String,
pub filter_variable: String,
pub filter_value: String,
pub order_by: String,
pub sort_order: String,
pub count: isize,
pub offset: isize,
pub limit: isize,
pub seriess: Vec<SeriesItem>,
}
/// See [Fred docs: /fred/series/vintage_dates](https://fred.stlouisfed.org/docs/api/fred/series_vintagedates.html).
#[derive(Debug, Deserialize)]
pub struct SeriesVintageDates {
pub realtime_start: String,
pub realtime_end: String,
pub order_by: String,
pub sort_order: String,
pub count: isize,
pub offset: isize,
pub limit: isize,
pub vintage_dates: Vec<String>,
}
/// See [Fred docs: /fred/sources](https://fred.stlouisfed.org/docs/api/fred/sources.html).
#[derive(Debug, Deserialize)]
pub struct Sources {
pub realtime_start: String,
pub realtime_end: String,
pub order_by: String,
pub sort_order: String,
pub count: isize,
pub offset: isize,
pub limit: isize,
pub sources: Vec<SourceItem>,
}
/// See [Fred docs: /fred/source/releases](https://fred.stlouisfed.org/docs/api/fred/source_releases.html).
#[derive(Debug, Deserialize)]
pub struct SourceReleases {
pub realtime_start: String,
pub realtime_end: String,
pub order_by: String,
pub sort_order: String,
pub count: isize,
pub offset: isize,
pub limit: isize,
pub releases: Vec<ReleaseItem>,
}
/// See [Fred docs: /fred/tags](https://fred.stlouisfed.org/docs/api/fred/tags.html).
#[derive(Debug, Deserialize)]
pub struct Tags {
pub realtime_start: String,
pub realtime_end: String,
pub order_by: String,
pub sort_order: String,
pub count: isize,
pub offset: isize,
pub limit: isize,
pub tags: Vec<Tag>,
}
impl fmt::Display for Tags {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut tags = String::new();
for tag in &self.tags {
tags.push_str(&tag.to_string());
tags.push('\n');
tags.push('\n');
};
write!(f, "{}", tags)
}
}
/// See [Fred docs: /fred/tags/series](https://fred.stlouisfed.org/docs/api/fred/tags_series.html).
#[derive(Debug, Deserialize)]
pub struct TagsSeries {
pub realtime_start: String,
pub realtime_end: String,
pub order_by: String,
pub sort_order: String,
pub count: isize,
pub offset: isize,
pub limit: isize,
pub seriess: Vec<SeriesItem>,
}
impl fmt::Display for TagsSeries {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut series = String::new();
for (i, s) in self.seriess.iter().enumerate() {
series.push_str(&format!("{}\n", i));
series.push_str(&s.to_string());
series.push('\n');
};
write!(f, "{}", series)
}
}