Skip to main content

ECBDataPortal

Struct ECBDataPortal 

Source
pub struct ECBDataPortal;
Expand description

European Central Bank Data Portal data collection backend.

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

Source

pub async fn get_data<Tz, T>( q: &Query, parameters: Option<Vec<DataParameter<Tz>>>, ) -> Result<T, Error>
where Tz: TimeZone, <Tz as TimeZone>::Offset: Display, T: DeserializeOwned,

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());
 
}
Source

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())
 
}
Source

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())
 
}

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more