Skip to main content

EstatApi

Struct EstatApi 

Source
pub struct EstatApi { /* private fields */ }
Expand description

Client for the e-Stat API v3.0 (JSON).

The application ID is issued after registering on e-Stat and is sent as the appId query parameter.

§Example

use estat_api::{Dimension, EstatApi, StatsDataParams, StatsListParams};

let api = EstatApi::from_env()?;

let list = api.stats_list(&StatsListParams::new().search_word("人口推計").limit(5)).await?;
for table in &list.datalist_inf.table_inf {
    println!("{} {:?}", table.id, table.title.as_ref().map(|t| &t.name));
}

let data = api
    .stats_data_all(&StatsDataParams::table("0003448237").code(Dimension::Area, "13000"))
    .await?;
for value in data.values() {
    println!("{:?} {}", data.label(value, Dimension::Time), value.value);
}

Implementations§

Source§

impl EstatApi

Source

pub fn with_app_id<T: Into<String>>(app_id: T) -> Self

Client with the given application ID. Requests time out after 5 minutes.

Source

pub fn from_env() -> Result<Self, EstatError>

Client with the application ID in the ESTAT_APP_ID environment variable.

§Errors

EstatError::InvalidArgument when the variable is not set or empty.

Source

pub fn with_client(self, client: Client) -> Self

Uses the given HTTP client, for example one with a proxy. The 5 minute default no longer applies, so set a timeout on the client if you want one.

Source

pub fn with_timeout(self, timeout: Duration) -> Self

Timeout for each request, including reading the body.

Source

pub fn with_lang(self, lang: Lang) -> Self

Language of the responses. Without it e-Stat answers in Japanese.

Source

pub fn with_base_url<T: Into<String>>(self, base_url: T) -> Self

Changes the API base URL (default https://api.e-stat.go.jp/rest/3.0/app/json). Mainly for tests against a mock server.

Source

pub async fn stats_list( &self, params: &StatsListParams, ) -> Result<StatsList, EstatError>

Searches statistical tables (getStatsList, 統計表情報取得).

§Errors
Source

pub async fn meta_info( &self, params: impl Into<MetaInfoParams>, ) -> Result<MetaInfo, EstatError>

Dimensions and items of a table (getMetaInfo, メタ情報取得). Takes a table ID or MetaInfoParams.

§Errors

EstatError::Api with 300 (see EstatError::is_not_found) when no table has the ID. Otherwise the same as stats_list.

Source

pub async fn stats_data( &self, params: &StatsDataParams, ) -> Result<StatsData, EstatError>

One page of values of a table or dataset (getStatsData, 統計データ取得).

A page holds up to limit values (100,000 by default). When there are more, StatsData::next_key is the start of the next page; pass it to StatsDataParams::start_position, or use stats_data_all.

§Errors

Same as meta_info.

Source

pub async fn stats_data_all( &self, params: &StatsDataParams, ) -> Result<StatsData, EstatError>

All values, following NEXT_KEY until the last page.

The first page is requested with params as given; later pages are requested without metadata. The result has the table and metadata of the first page and the values of all pages, with NEXT_KEY cleared. Large tables take many requests, so narrow them down with filters.

§Errors

Same as stats_data, and EstatError::UnexpectedResponse if NEXT_KEY does not move forward.

Source

pub async fn data_catalog( &self, params: &DataCatalogParams, ) -> Result<DataCatalog, EstatError>

Searches the data catalog: Excel, CSV and PDF files and database tables on e-Stat (getDataCatalog, データカタログ情報取得).

§Errors

Same as stats_list.

Source

pub async fn stats_datas( &self, params: &StatsDatasParams, ) -> Result<StatsDatas, EstatError>

Values of several tables or datasets in one request (getStatsDatas, 統計データ一括取得). The requests together may return at most 100,000 values, and there is no paging; use stats_data for more.

§Errors

EstatError::Api with 400 when the requests select too many values, or 401 when one of them fails (the message names the request and its error). Otherwise the same as stats_list.

Source

pub async fn datasets( &self, params: &DatasetsParams, ) -> Result<DatasetList, EstatError>

Datasets you can use: your own and those others made public (refDataset without an ID, データセット参照).

§Errors

Same as stats_list.

Source

pub async fn dataset( &self, params: impl Into<DatasetParams>, ) -> Result<RefDataset, EstatError>

One dataset with its filters (refDataset with an ID, データセット参照). Takes a dataset ID or DatasetParams.

§Errors

EstatError::Api with 300 when there is no dataset with that ID. Otherwise the same as stats_list.

Source

pub async fn post_dataset( &self, params: &PostDatasetParams, ) -> Result<PostDataset, EstatError>

Registers, updates or deletes a dataset (postDataset, データセット登録).

This changes data on e-Stat under your application ID. e-Stat answers this call in XML only, and it is sent to postDataset next to the json directory of the base URL.

§Errors

EstatError::Api with 101 to 104 for missing or invalid parameters, 301 when the dataset belongs to another application ID, 302 when the filters select nothing. Otherwise the same as stats_list.

Trait Implementations§

Source§

impl Clone for EstatApi

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for EstatApi

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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: Sized + 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: Sized + 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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