hdx

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package hdx is the library behind the hdx command line: the HTTP client, request shaping, and the typed data models for the Humanitarian Data Exchange (HDX) API.

HDX (data.humdata.org) is a CKAN-based open humanitarian data platform run by OCHA. Every action endpoint lives under /api/action/<name> and returns {"success": true, "result": <payload>}. No API key or cookie required.

The Client sets a real User-Agent, paces requests so a busy session stays polite, and retries transient failures (429 and 5xx).

Index

Constants

View Source
const BaseURL = "https://data.humdata.org/api/action"

BaseURL is the CKAN API root every request is built from.

View Source
const DefaultUserAgent = "hdx-cli/0.1 (tamnd87@gmail.com)"

DefaultUserAgent identifies the client to HDX.

View Source
const Host = "data.humdata.org"

Host is the HDX site hostname.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	HTTP      *http.Client
	UserAgent string
	// Rate is the minimum gap between requests.
	Rate    time.Duration
	Retries int
	// contains filtered or unexported fields
}

Client talks to the HDX CKAN API over HTTP.

func NewClient

func NewClient() *Client

NewClient returns a Client with sensible defaults: 30s timeout, 300ms minimum gap between requests, and 3 retries on transient errors.

func (*Client) Get

func (c *Client) Get(ctx context.Context, rawURL string) ([]byte, error)

Get fetches rawURL and returns the response body. It paces and retries according to the client's settings.

func (*Client) GetPackage

func (c *Client) GetPackage(ctx context.Context, name string) (*Package, []*Resource, error)

GetPackage fetches a single dataset by name/slug and returns the summary record plus all resource records.

func (*Client) ListOrganizations

func (c *Client) ListOrganizations(ctx context.Context, limit int) ([]*Organization, error)

ListOrganizations returns HDX organizations.

func (*Client) SearchDatasets

func (c *Client) SearchDatasets(ctx context.Context, query string, limit int, org string) ([]*Dataset, error)

SearchDatasets searches HDX datasets by keyword. org filters by organization name slug if non-empty.

type Dataset

type Dataset struct {
	Name         string `kit:"id" json:"name"`
	Title        string `json:"title"`
	Organization string `json:"organization"`
	Resources    int    `json:"resources"`
	Modified     string `json:"modified"`
	Tags         string `json:"tags"` // comma-joined first 3 tags
}

Dataset is one search result record.

type Domain

type Domain struct{}

Domain is the hdx driver. It carries no state; the per-run client is built by the factory Register hands kit.

func (Domain) Classify

func (Domain) Classify(input string) (uriType, id string, err error)

Classify turns a dataset name or HDX URL into a (type, id).

func (Domain) Info

func (Domain) Info() kit.DomainInfo

Info describes the scheme, the hostnames a pasted link is matched against, and the identity reused for the binary's help and version.

func (Domain) Locate

func (Domain) Locate(uriType, id string) (string, error)

Locate returns the live https URL for a (type, id).

func (Domain) Register

func (Domain) Register(app *kit.App)

Register installs the client factory and every operation onto app.

type Organization

type Organization struct {
	Name         string `kit:"id" json:"name"`
	Title        string `json:"title"`
	PackageCount int    `json:"package_count"`
}

Organization is one HDX contributing organization.

type Package

type Package struct {
	Name         string `kit:"id" json:"name"`
	Title        string `json:"title"`
	Organization string `json:"organization"`
	Description  string `json:"description"` // truncated notes
	Modified     string `json:"modified"`
	Resources    int    `json:"resources"`
}

Package is the summary record for a dataset.

type Resource

type Resource struct {
	Name        string `kit:"id" json:"name"`
	Format      string `json:"format"`
	URL         string `json:"url" table:"url,url"`
	Description string `json:"description"`
}

Resource is one file attached to a dataset.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL