First record
[?]
Feb 27, 2021, 4:55 AM
AZQVIGSM6OJHNHTTWY3X5D6YEYWQ5IXNJ2OM7DDVP2MPJ3R37MTACDependencies
Change contents
- file addition: tests[1.0]
- file addition: test.rs[0.8]
use fred_api::Fred;use rand;use std::time::Duration;use std::thread::sleep;#[test]fn category() {wait();Fred::category(1);}#[test]fn category_children() {wait();Fred::category_children(1);}#[test]fn category_related() {wait();Fred::category_related(4);}#[test]fn category_series() {wait();Fred::category_series(4); }#[test]fn category_tags() {wait();Fred::category_tags(4);}#[test]fn category_related_tags() {wait();Fred::category_related_tags(4, "potatoes");}#[test]fn releases() {wait();Fred::releases();}#[test]fn releases_date() {wait();Fred::releases_dates();}#[test]fn release() {wait();Fred::release(478);}#[test]fn release_date() {wait();Fred::release_dates(478);}#[test]fn release_series() {wait();Fred::release_series(478);}#[test]fn release_sources() {wait();Fred::release_sources(478);}#[test]fn release_tags() {wait();Fred::release_tags(478);}#[test]fn release_related_tags() {wait();Fred::release_related_tags(478, "potatoes");}// TODO Fred::release_tables(478);#[test]fn series() {wait();Fred::series("LRUNTTTTAUM156S");}#[test]fn series_categories() {wait();Fred::series_categories("LRUNTTTTAUM156S");}#[test]fn series_observations() {wait();Fred::series_observations("LRUNTTTTAUM156S");}#[test]fn series_release() {wait();Fred::series_release("LRUNTTTTAUM156S");}#[test]fn series_search() {wait();Fred::series_search("unemployment");}#[test]fn series_search_tags() {wait();Fred::series_search_tags("unemployment");}#[test]fn series_search_related_tags() {wait();Fred::series_search_related_tags("unemployment", "rate");}#[test]fn series_tags() {wait();Fred::series_tags("LRUNTTTTAUM156S");}#[test]fn series_updates() {wait();Fred::series_updates();}#[test]fn series_vintagedates() {wait();Fred::series_vintagedates("LRUNTTTTAUM156S");}#[test]fn sources() {wait();Fred::sources();}#[test]fn source() {wait();Fred::source(1);}#[test]fn source_releases() {wait();Fred::source_releases(1);}#[test]fn tags() {wait();Fred::tags();}#[test]fn related_tags() {wait();Fred::related_tags("unemployment");}#[test]fn tags_series() {wait();Fred::tags_series("unemployment");}fn wait() {let r = rand::random::<u8>();sleep(Duration::from_secs((r / 5).into()));} - file addition: src[1.0]
- file addition: response.rs[0.2628]
//! 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)}} - file addition: lib.rs[0.2628]
//! [Fred API key](https://fred.stlouisfed.org/docs/api/api_key.html) needs to//! be stored as the environment variable FRED_API_KEY.//! ```//! use fred_api::Fred;//! use fred_api::response::Categories;//!//! let categories = Fred::category(125);use std::env;use std::fs;use crate::response::*;pub mod response;pub struct Fred;impl Fred {/// [Get a category](https://fred.stlouisfed.org/docs/api/fred/category.html)pub fn category(category_id: usize) -> Categories {serde_json::from_str(&response("category",vec!(format!("category_id={}", category_id)),)).unwrap()}/// [Get the child categories for a specified parent category.](https://fred.stlouisfed.org/docs/api/fred/category_children.html)pub fn category_children(category_id: usize) -> Categories {serde_json::from_str(&response("category/children",vec!(format!("category_id={}", category_id)),)).unwrap()}/// [Get the related categories for a category.](https://fred.stlouisfed.org/docs/api/fred/category_related.html)pub fn category_related(category_id: usize) -> Categories {serde_json::from_str(&response("category/related",vec!(format!("category_id={}", category_id)),)).unwrap()}/// [Get the series in a category.](https://fred.stlouisfed.org/docs/api/fred/category_series.html)pub fn category_series(category_id: usize) -> CategorySeries {serde_json::from_str(&response("category/series",vec!(format!("category_id={}", category_id)),)).unwrap()}/// [Get the tags for a category.](https://fred.stlouisfed.org/docs/api/fred/category_tags.html)pub fn category_tags(category_id: usize) -> CategoryTags {serde_json::from_str(&response("category/tags",vec!(format!("category_id={}", category_id)),)).unwrap()}/// [Get the related tags for a category.](https://fred.stlouisfed.org/docs/api/fred/category_related_tags.html)pub fn category_related_tags(category_id: usize, tag_names: &str) -> CategoryRelatedTags {serde_json::from_str(&response("category/related_tags",vec!(format!("category_id={}", category_id),format!("tag_names={}", tag_names),),)).unwrap()}/// [Get all releases of economic data.](https://fred.stlouisfed.org/docs/api/fred/releases.html)pub fn releases() -> Releases {serde_json::from_str(&response("releases",Vec::new(),)).unwrap()}/// [Get release dates for all releases of economic data.](https://fred.stlouisfed.org/docs/api/fred/releases_dates.html)pub fn releases_dates() -> ReleaseDates {serde_json::from_str(&response("releases/dates",Vec::new(),)).unwrap()}/// [Get a release of economic data.](https://fred.stlouisfed.org/docs/api/fred/release.html)pub fn release(release_id: usize) -> Release {serde_json::from_str(&response("release",vec!(format!("release_id={}", release_id)),)).unwrap()}/// [Get release dates for a release of economic data.](https://fred.stlouisfed.org/docs/api/fred/release_dates.html)pub fn release_dates(release_id: usize) -> ReleaseDates {serde_json::from_str(&response("release/dates",vec!(format!("release_id={}", release_id)),)).unwrap()}/// [Get the series on a release of economic data.](https://fred.stlouisfed.org/docs/api/fred/release_series.html)pub fn release_series(release_id: usize) -> ReleaseSeries {serde_json::from_str(&response("release/series",vec!(format!("release_id={}", release_id)),)).unwrap()}/// [Get the sources for a release of economic data.](https://fred.stlouisfed.org/docs/api/fred/release_sources.html)pub fn release_sources(release_id: usize) -> ReleaseSources {serde_json::from_str(&response("release/sources",vec!(format!("release_id={}", release_id)),)).unwrap()}/// [Get the tags for a release.](https://fred.stlouisfed.org/docs/api/fred/release_tags.html)pub fn release_tags(release_id: usize) -> ReleaseTags {serde_json::from_str(&response("release/tags",vec!(format!("release_id={}", release_id)),)).unwrap()}/// [Get the related tags for a release.](https://fred.stlouisfed.org/docs/api/fred/release_related_tags.html)pub fn release_related_tags(release_id: usize, tag_names: &str) -> ReleaseRelatedTags {serde_json::from_str(&response("release/related_tags",vec!(format!("release_id={}", release_id),format!("tag_names={}", tag_names),),)).unwrap()}/// [Get the release tables for a given release.](https://fred.stlouisfed.org/docs/api/fred/release_tables.html)pub fn release_tables(release_id: usize) -> ReleaseTables {serde_json::from_str(&response("release/tables",vec!(format!("release_id={}", release_id)),)).unwrap()}/// [Get an economic data series.](https://fred.stlouisfed.org/docs/api/fred/series.html)pub fn series(series_id: &str) -> Series {serde_json::from_str(&response("series",vec!(format!("series_id={}", series_id)),)).unwrap()}/// [Get the categories for an economic data series.](https://fred.stlouisfed.org/docs/api/fred/series_categories.html)pub fn series_categories(series_id: &str) -> Categories {serde_json::from_str(&response("series/categories",vec!(format!("series_id={}", series_id)),)).unwrap()}/// [Get the observations or data values for an economic data series.](https://fred.stlouisfed.org/docs/api/fred/series_observations.html)pub fn series_observations(series_id: &str) -> SeriesObservations {serde_json::from_str(&response("series/observations",vec!(format!("series_id={}", series_id)),)).unwrap()}/// [Get the release for an economic data series.](https://fred.stlouisfed.org/docs/api/fred/series_release.html)pub fn series_release(series_id: &str) -> SeriesRelease {serde_json::from_str(&response("series/release",vec!(format!("series_id={}", series_id)),)).unwrap()}/// [Get economic data series that match keywords.](https://fred.stlouisfed.org/docs/api/fred/series_search.html)pub fn series_search(search_text: &str) -> SeriesSearch {serde_json::from_str(&response("series/search",vec!(format!("search_text={}", search_text)),)).unwrap()}/// [Get the tags for a series search.](https://fred.stlouisfed.org/docs/api/fred/series_search_tags.html)pub fn series_search_tags(series_search_text: &str) -> SeriesSearchTags {serde_json::from_str(&response("series/search/tags",vec!(format!("series_search_text={}", series_search_text)),)).unwrap()}/// [Get the related tags for a series search.](https://fred.stlouisfed.org/docs/api/fred/series_search_related_tags.html)pub fn series_search_related_tags(series_search_text: &str, tag_names: &str) -> SeriesSearchRelatedTags {serde_json::from_str(&response("series/search/related_tags",vec!(format!("series_search_text={}", series_search_text),format!("tag_names={}", tag_names),),)).unwrap()}/// [Get the tags for an economic data series.](https://fred.stlouisfed.org/docs/api/fred/series_tags.html)pub fn series_tags(series_id: &str) -> SeriesTags {serde_json::from_str(&response("series/tags",vec!(format!("series_id={}", series_id)),)).unwrap()}/// [Get economic data series sorted by when observations were updated on the FRED® server.](https://fred.stlouisfed.org/docs/api/fred/series_updates.html)pub fn series_updates() -> SeriesUpdates {serde_json::from_str(&response("series/updates",Vec::new(),)).unwrap()}/// [Get the dates in history when a series' data values were revised or new data values were released.](https://fred.stlouisfed.org/docs/api/fred/series_vintagedates.html)pub fn series_vintagedates(series_id: &str) -> SeriesVintageDates {serde_json::from_str(&response("series/vintagedates",vec!(format!("series_id={}", series_id)),)).unwrap()}/// [Get all sources of economic data.](https://fred.stlouisfed.org/docs/api/fred/sources.html)pub fn sources() -> Sources {serde_json::from_str(&response("sources",Vec::new(),)).unwrap()}/// [Get a source of economic data.](https://fred.stlouisfed.org/docs/api/fred/source.html)pub fn source(source_id: usize) -> ReleaseSources {serde_json::from_str(&response("source",vec!(format!("source_id={}", source_id)),)).unwrap()}/// [Get the releases for a source.](https://fred.stlouisfed.org/docs/api/fred/source_releases.html)pub fn source_releases(source_id: usize) -> SourceReleases {serde_json::from_str(&response("source/releases",vec!(format!("source_id={}", source_id)),)).unwrap()}/// [Get all tags, search for tags, or get tags by name.](https://fred.stlouisfed.org/docs/api/fred/tags.html)pub fn tags() -> Tags {serde_json::from_str(&response("tags",Vec::new(),)).unwrap()}/// [Get the related tags for one or more tags.](https://fred.stlouisfed.org/docs/api/fred/related_tags.html)pub fn related_tags(tag_names: &str) -> Tags {serde_json::from_str(&response("related_tags",vec!(format!("tag_names={}", tag_names)),)).unwrap()}/// [Get the series matching tags.](https://fred.stlouisfed.org/docs/api/fred/tags_series.html)pub fn tags_series(tag_names: &str) -> TagsSeries {serde_json::from_str(&response("tags/series",vec!(format!("tag_names={}", tag_names)),)).unwrap()}}fn response(url: &str, keyvals: Vec<String>) -> String {json(&request_str(url, keyvals))}fn json(req: &str) -> String {let json = reqwest::blocking::get(req).unwrap().text_with_charset("utf-8").unwrap();fs::write("temp.json", &json).unwrap();json}fn request_str(url: &str, keyvals: Vec<String>) -> String {let mut s = format!("https://api.stlouisfed.org/fred/{}?",url,);for kv in keyvals {s.push_str(&kv);s.push('&');};s.push_str(&format!("api_key={}&file_type=json",env::var("FRED_API_KEY").unwrap(),));s} - file addition: Cargo.toml[1.0]
[package]name = "fred_api"version = "0.1.0"authors = ["Eric Findlay <e.findlay@protonmail.ch>"]edition = "2018"# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html[dependencies]rand = "0.8.0"reqwest = { version = "0.10", features = ["blocking", "json"] }serde = { version = "1.0", features = ["derive"] }serde_json = "1.0.60"[lib]doctest = false