ecbdp_api/lib.rs
1//! # ECB Data Portal API Wrapper
2//!
3//! `ecbdp-api` is a wrapper for European Central Bank (ECB) Data Portal. The data can be accessed using
4//! series keys, which can be found at the ECB Data Portal website:
5//! - <https://data.ecb.europa.eu/data/datasets>
6//!
7//! For more information on the ECB Data Portal API use the API documentation:
8//! - <https://data.ecb.europa.eu/help/api/overview>
9//!
10//! Note: On the ECB Data Portal, the series are prefixed with their flow identifier. For example,
11//! `EXR.M.USD.EUR.SP00.A` is the series key on the ECB Data Portal, but for the purpose of this crate `EXR` is a `flow_id`
12//! and `M.USD.EUR.SP00.A` is a `series_key`.
13//!
14//! **Disclaimer:** This crate is an unofficial ECB Data Portal wrapper, the maintainers of the crate are independent developers.
15//! The developers of the crate do not accept any responsibility or liability for the accuracy, security, or completeness of the code,
16//! or the information provided within the crate.
17//!
18//! # General information
19//! If you would like to add a commit or an issue, please do so using the GitHub link to the project:
20//! - <https://github.com/rsadykhov/ecbdp-api>
21//!
22//! # Examples
23//!
24//! 1. Query ECB Data Portal for data
25//!
26//! ```rust
27//! use chrono::{FixedOffset, DateTime, TimeZone};
28//! use ecbdp_api::{ECBDataPortal, Query, FlowRef, DataParameter, ECBResponse};
29//! use ecbdp_api::parameter::data::{Detail, Format};
30//!
31//! #[tokio::main]
32//! async fn main() -> () {
33//!
34//! // Query
35//! let q: Query = Query::new()
36//! .flow_ref(FlowRef { agency_id: None, flow_id: "EXR".to_owned(), version: None, })
37//! .series_key("M.USD.EUR.SP00.A");
38//!
39//! // Parameters
40//! let hour: i32 = 3600;
41//! let datetime: DateTime<FixedOffset> = FixedOffset::east_opt(1 * hour).unwrap()
42//! .with_ymd_and_hms(2009, 05, 15, 14, 15, 0).unwrap();
43//! let parameters: Option<Vec<DataParameter<FixedOffset>>> = Some(vec![
44//! DataParameter::UpdatedAfter { datetime, },
45//! DataParameter::Detail { detail: Detail::DataOnly, },
46//! DataParameter::Format { format: Format::JSONData, }
47//! ]);
48//!
49//! // Backend
50//! let ecb_response: ECBResponse = ECBDataPortal::get_data(&q, parameters).await.unwrap();
51//!
52//! assert!(0 < ecb_response.datasets[0].series.iter().last().unwrap().1.observations.as_ref().unwrap().len());
53//! assert_eq!(ecb_response.structure.name, "Exchange Rates".to_owned());
54//!
55//! }
56//! ```
57//!
58//! 2. Query ECB Data Portal for a schema
59//!
60//! ```rust
61//! use ecbdp_api::{ECBDataPortal, Query, Resource, Context};
62//!
63//! #[tokio::main]
64//! async fn main() -> () {
65//!
66//! // Query
67//! let q: Query = Query::new()
68//! .resource(Resource::Schema)
69//! .context(Context::DataStructure)
70//! .agency_id("ECB")
71//! .resource_id("ECB_EXR1")
72//! .version("1.0");
73//!
74//! // Backend
75//! let schema: String = ECBDataPortal::get_schema(&q).await.unwrap();
76//!
77//! assert!(!schema.is_empty())
78//!
79//! }
80//! ```
81//!
82//! 3. Query ECB Data Portal for metadata
83//!
84//! ```rust
85//! use ecbdp_api::{ECBDataPortal, Query, Resource};
86//!
87//! #[tokio::main]
88//! async fn main() -> () {
89//!
90//! // Query
91//! let q: Query = Query::new()
92//! .resource(Resource::MetadataDataStructure)
93//! .agency_id("ECB")
94//! .resource_id("ECB_EXR1")
95//! .version("latest");
96//!
97//! // Backend
98//! let metadata: String = ECBDataPortal::get_metadata(&q, None).await.unwrap();
99//!
100//! assert!(!metadata.is_empty())
101//!
102//! }
103//! ```
104
105
106// Re-Exports
107pub use self::backend::ECBDataPortal;
108pub use self::parameter::{data::DataParameter, metadata::MetadataParameter};
109pub use self::query::{Protocol, WSEntryPoint, Resource, FlowRef, Context, Query};
110pub use self::schemas::ECBResponse;
111
112
113pub mod backend;
114pub mod error;
115pub mod parameter;
116pub mod query;
117pub mod schemas;
118pub mod time;