Skip to main content

DataGovClient

Struct DataGovClient 

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

Async client for exploring data.gov datasets.

DataGovClient layers ergonomic helpers on top of data_gov_catalog::CatalogClient. In addition to search and metadata lookups it handles download destinations, progress reporting, and status-reporter integration used by the data-gov CLI.

Implementations§

Source§

impl DataGovClient

Source

pub fn new() -> Result<Self>

Create a new DataGov client with default configuration.

Source

pub fn config(&self) -> &DataGovConfig

Access the current configuration.

Source

pub fn with_config(config: DataGovConfig) -> Result<Self>

Create a new DataGov client with custom configuration.

Source

pub async fn search( &self, query: &str, per_page: Option<i32>, after: Option<&str>, organization: Option<&str>, ) -> Result<SearchResponse>

Search for datasets on data.gov.

§Arguments
  • query - Full-text query (searches titles, descriptions, keywords). Pass an empty string to search without a text query.
  • per_page - Page size. Server default is 10.
  • after - Opaque cursor returned by a previous page’s SearchResponse::after. Pass None for the first page.
  • organization - Organization slug (e.g. nasa) to filter by.

Pagination is cursor-based; there is no random-access offset.

§Examples
let client = DataGovClient::new()?;
let page = client.search("climate", Some(20), None, None).await?;
let next = client.search("climate", Some(20), page.after.as_deref(), None).await?;
Source

pub async fn get_dataset(&self, slug: &str) -> Result<SearchHit>

Fetch a single dataset by its data.gov slug.

Returns Err(ResourceNotFound) if no dataset matches.

Source

pub async fn get_dataset_by_harvest_record(&self, id: &str) -> Result<Dataset>

Fetch the DCAT-US 3 record for a harvest-record UUID.

Source

pub async fn autocomplete_datasets( &self, partial: &str, limit: Option<i32>, ) -> Result<Vec<String>>

Fetch dataset title suggestions for interactive prompts.

Implemented as a capped full-text search; the new API does not offer a dedicated dataset-autocomplete endpoint.

Source

pub async fn list_organizations( &self, limit: Option<i32>, ) -> Result<Vec<String>>

List the publisher slugs for government organizations, capped to limit.

Source

pub async fn list_organization_records(&self) -> Result<Vec<Organization>>

Fetch full organization records for the catalog.

Source

pub async fn autocomplete_organizations( &self, partial: &str, limit: Option<i32>, ) -> Result<Vec<String>>

Fetch organization name suggestions matching partial.

Implemented as a client-side case-insensitive filter over CatalogClient::organizations.

Source

pub fn get_downloadable_distributions(dataset: &Dataset) -> Vec<Distribution>

Return distributions that look like downloadable files.

A distribution qualifies when it carries a downloadURL (as opposed to API-only accessURL entries).

Source

pub fn get_distribution_filename( distribution: &Distribution, fallback_name: Option<&str>, index: Option<usize>, ) -> String

Pick a filesystem-friendly filename for a distribution.

§Arguments
  • distribution - The distribution to generate a filename for.
  • fallback_name - Used when the distribution has no title and no URL segment we can derive a name from.
  • index - Appended before the extension to disambiguate multi-file batches with duplicate titles.
Source

pub async fn download_distribution( &self, distribution: &Distribution, output_dir: Option<&Path>, ) -> Result<PathBuf>

Download a single distribution to the specified directory.

§Arguments
  • distribution - The distribution to download.
  • output_dir - Directory where the file will be saved. If None, uses the configured base download directory.

Returns the path where the file was written.

Source

pub async fn download_distributions( &self, distributions: &[Distribution], output_dir: Option<&Path>, ) -> Vec<Result<PathBuf>>

Download multiple distributions concurrently.

Returns one Result per distribution so callers can inspect partial failures.

Source

pub async fn validate_download_dir(&self) -> Result<()>

Check that the base download directory exists and is writable.

Source

pub fn download_dir(&self) -> PathBuf

Get the current base download directory.

Source

pub fn catalog_client(&self) -> &CatalogClient

Get the underlying Catalog API client for advanced operations.

Trait Implementations§

Source§

impl Debug for DataGovClient

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> 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, 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