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
impl DataGovClient
Sourcepub fn config(&self) -> &DataGovConfig
pub fn config(&self) -> &DataGovConfig
Access the current configuration.
Sourcepub fn with_config(config: DataGovConfig) -> Result<Self>
pub fn with_config(config: DataGovConfig) -> Result<Self>
Create a new DataGov client with custom configuration.
Sourcepub async fn search(
&self,
query: &str,
per_page: Option<i32>,
after: Option<&str>,
organization: Option<&str>,
) -> Result<SearchResponse>
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’sSearchResponse::after. PassNonefor 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?;Sourcepub async fn get_dataset(&self, slug: &str) -> Result<SearchHit>
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.
Sourcepub async fn get_dataset_by_harvest_record(&self, id: &str) -> Result<Dataset>
pub async fn get_dataset_by_harvest_record(&self, id: &str) -> Result<Dataset>
Fetch the DCAT-US 3 record for a harvest-record UUID.
Sourcepub async fn autocomplete_datasets(
&self,
partial: &str,
limit: Option<i32>,
) -> Result<Vec<String>>
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.
Sourcepub async fn list_organizations(
&self,
limit: Option<i32>,
) -> Result<Vec<String>>
pub async fn list_organizations( &self, limit: Option<i32>, ) -> Result<Vec<String>>
List the publisher slugs for government organizations, capped to limit.
Sourcepub async fn list_organization_records(&self) -> Result<Vec<Organization>>
pub async fn list_organization_records(&self) -> Result<Vec<Organization>>
Fetch full organization records for the catalog.
Sourcepub async fn autocomplete_organizations(
&self,
partial: &str,
limit: Option<i32>,
) -> Result<Vec<String>>
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.
Sourcepub fn get_downloadable_distributions(dataset: &Dataset) -> Vec<Distribution>
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).
Sourcepub fn get_distribution_filename(
distribution: &Distribution,
fallback_name: Option<&str>,
index: Option<usize>,
) -> String
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.
Sourcepub async fn download_distribution(
&self,
distribution: &Distribution,
output_dir: Option<&Path>,
) -> Result<PathBuf>
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. IfNone, uses the configured base download directory.
Returns the path where the file was written.
Sourcepub async fn download_distributions(
&self,
distributions: &[Distribution],
output_dir: Option<&Path>,
) -> Vec<Result<PathBuf>> ⓘ
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.
Sourcepub async fn validate_download_dir(&self) -> Result<()>
pub async fn validate_download_dir(&self) -> Result<()>
Check that the base download directory exists and is writable.
Sourcepub fn download_dir(&self) -> PathBuf
pub fn download_dir(&self) -> PathBuf
Get the current base download directory.
Sourcepub fn catalog_client(&self) -> &CatalogClient
pub fn catalog_client(&self) -> &CatalogClient
Get the underlying Catalog API client for advanced operations.