pub struct ECBDataPortal;Expand description
European Central Bank Data Portal data collection backend.
- For API details refrence: https://data.ecb.europa.eu/help/api/overview
- For available data sets reference: https://data.ecb.europa.eu/data/datasets
Note: On the ECB Data Portal the series are prefixed with their flow identifier. For example,
EXR.M.USD.EUR.SP00.A is the series key on the ECB Data Portal, but EXR is an flow_id and M.USD.EUR.SP00.A
is the series_key in this implementation.
Implementations§
Source§impl ECBDataPortal
impl ECBDataPortal
Sourcepub async fn get_data<Tz, T>(
q: &Query,
parameters: Option<Vec<DataParameter<Tz>>>,
) -> Result<T, Error>
pub async fn get_data<Tz, T>( q: &Query, parameters: Option<Vec<DataParameter<Tz>>>, ) -> Result<T, Error>
Sends a data resource request provided the constructed query and the list of parameters.
§Examples
use chrono::{FixedOffset, DateTime, TimeZone};
use ecbdp_api::{ECBDataPortal, Query, FlowRef, DataParameter, ECBResponse};
use ecbdp_api::parameter::data::{Detail, Format};
#[tokio::main]
async fn main() -> () {
// Query
let q: Query = Query::new()
.flow_ref(FlowRef { agency_id: None, flow_id: "EXR".to_owned(), version: None, })
.series_key("M.USD.EUR.SP00.A");
// Parameters
let hour: i32 = 3600;
let datetime: DateTime<FixedOffset> = FixedOffset::east_opt(1 * hour).unwrap()
.with_ymd_and_hms(2009, 05, 15, 14, 15, 0).unwrap();
let parameters: Option<Vec<DataParameter<FixedOffset>>> = Some(vec![
DataParameter::UpdatedAfter { datetime, },
DataParameter::Detail { detail: Detail::DataOnly, },
DataParameter::Format { format: Format::JSONData, }
]);
// Backend
let ecb_response: ECBResponse = ECBDataPortal::get_data(&q, parameters).await.unwrap();
assert!(0 < ecb_response.datasets[0].series.iter().last().unwrap().1.observations.as_ref().unwrap().len());
assert_eq!(ecb_response.structure.name, "Exchange Rates".to_owned());
}Sourcepub async fn get_schema(q: &Query) -> Result<String, Error>
pub async fn get_schema(q: &Query) -> Result<String, Error>
Sends a schema resource request provided the constructed query.
Note: The returned type is a String, which is just a text body of the response and it can be further deserialized
if the appropriate deserializetion traget struct is provided.
§Examples
use ecbdp_api::{ECBDataPortal, Query, Resource, Context};
#[tokio::main]
async fn main() -> () {
// Query
let q: Query = Query::new()
.resource(Resource::Schema)
.context(Context::DataStructure)
.agency_id("ECB")
.resource_id("ECB_EXR1")
.version("1.0");
// Backend
let schema: String = ECBDataPortal::get_schema(&q).await.unwrap();
assert!(!schema.is_empty())
}Sourcepub async fn get_metadata(
q: &Query,
parameters: Option<Vec<MetadataParameter>>,
) -> Result<String, Error>
pub async fn get_metadata( q: &Query, parameters: Option<Vec<MetadataParameter>>, ) -> Result<String, Error>
Sends a metadata resource request provided the constructed query and the list of parameters.
Note: The returned type is a String, which is just a text body of the response and it can be further deserialized
if the appropriate deserializetion traget struct is provided.
§Examples
use ecbdp_api::{ECBDataPortal, Query, Resource};
#[tokio::main]
async fn main() -> () {
// Query
let q: Query = Query::new()
.resource(Resource::MetadataDataStructure)
.agency_id("ECB")
.resource_id("ECB_EXR1")
.version("latest");
// Backend
let metadata: String = ECBDataPortal::get_metadata(&q, None).await.unwrap();
assert!(!metadata.is_empty())
}