Crates.io | abs-data |
lib.rs | abs-data |
version | 0.2.2 |
source | src |
created_at | 2023-10-08 07:12:24.711328 |
updated_at | 2024-11-10 03:04:49.694595 |
description | DEPRECATED AND NO LONGER MAINTAINED DO NOT USE |
homepage | |
repository | https://github.com/MitchellRhysHall/abs-data |
max_upload_size | |
id | 996960 |
size | 58,031 |
This crate was based on the beta version of the ABS DATA API
As of November 29th 2024 the ABS DATA API is moving to SDMX 3.0 among other breaking changes.
Please move to using the API directly at https://api.data.abs.gov.au/rest/data
DO NOT USE THIS CRATE
This Rust library provides a convenient way to interact with the Australian Bureau of Statistics (ABS) Data API https://api.gov.au/assets/APIs/abs/DataAPI.openapi.html. It Utilizes builder types for fluent requests to the API.
Add this to your Cargo.toml
:
[dependencies]
abs_data = "0.2.1"
Example requests:
use abs_data::{
builders::{
dataflow_identifier_builder::DataflowIdentifierBuilder,
datakey_builder::DataKeyBuilder, sdmx_data_request_builder::SdmxDataRequestBuilder,
sdmx_meta_request_builder::SdmxMetaRequestBuilder,
},
models::typed::{
datakey::DataKey, datakey_dimension::DataKeyDimension, detail::Detail, period::Period,
structure_type::StructureType,
},
result::Result,
};
async fn get_dynamic_meta_and_use_for_request() -> Result<()> {
let meta_response = SdmxMetaRequestBuilder::new(&StructureType::DataFlow)
.build()
.send()
.await?;
let dataflow = &meta_response.data.dataflows.unwrap()[10]; // Select desired dataflow
let dataflow_identifier = DataflowIdentifierBuilder::new(&dataflow.id)
.agency_id(&dataflow.agency_id)
.version(&dataflow.version)
.build();
let _response = SdmxDataRequestBuilder::new(&dataflow_identifier)
.detail(&Detail::DataOnly)
.start_period(&Period::Year(2012))
.end_period(&Period::Year(2022))
.build()
.send()
.await?;
Ok(())
}
async fn get_all_data_for_structure_id_without_filter() -> Result<()> {
let dataflow_identifier = DataflowIdentifierBuilder::new("CPI").build();
let _response = SdmxDataRequestBuilder::new(&dataflow_identifier) // Avoid 500 response with data only detail (issue with beta api)
.build()
.send()
.await?;
Ok(())
}
async fn get_datakeys_for_structure_id() -> Result<()> {
let dataflow_identifier = DataflowIdentifierBuilder::new("CPI").build();
let _response = SdmxDataRequestBuilder::new(&dataflow_identifier)
.detail(&Detail::SeriesKeysOnly)
.build()
.send()
.await?;
Ok(())
}
async fn get_data_with_custom_datakey() -> Result<()> {
let dataflow_identifier = DataflowIdentifierBuilder::new("CPI").build();
let _response = SdmxDataRequestBuilder::new(&dataflow_identifier)
.data_key(&DataKey::parse("1.40066.10.8.Q")?)
.detail(&Detail::DataOnly)
.build()
.send()
.await?;
Ok(())
}
async fn get_data_with_datakey_builder_validation() -> Result<()> {
let dataflow_identifier = DataflowIdentifierBuilder::new("CPI").build();
let key = DataKeyBuilder::new(&dataflow_identifier)
.add(&DataKeyDimension::new("MEASURE", "1"))
.add(&DataKeyDimension::new("INDEX", "40066"))
.add(&DataKeyDimension::new("REGION", "8"))
.add(&DataKeyDimension::new("FREQ", "Q"))
.add(&DataKeyDimension::new("TSEST", "10"))
.build()
.await?;
assert_eq!(key, DataKey::parse("1.40066.10.8.Q")?);
let _response = SdmxDataRequestBuilder::new(&dataflow_identifier)
.data_key(&key)
.detail(&Detail::DataOnly)
.build()
.send()
.await?;
Ok(())
}