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
- type Client
- func (c *Client) Get(ctx context.Context, rawURL string) ([]byte, error)
- func (c *Client) GetPackage(ctx context.Context, name string) (*Package, []*Resource, error)
- func (c *Client) ListOrganizations(ctx context.Context, limit int) ([]*Organization, error)
- func (c *Client) SearchDatasets(ctx context.Context, query string, limit int, org string) ([]*Dataset, error)
- type Dataset
- type Domain
- type Organization
- type Package
- type Resource
Constants ¶
const BaseURL = "https://data.humdata.org/api/action"
BaseURL is the CKAN API root every request is built from.
const DefaultUserAgent = "hdx-cli/0.1 (tamnd87@gmail.com)"
DefaultUserAgent identifies the client to HDX.
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 ¶
Get fetches rawURL and returns the response body. It paces and retries according to the client's settings.
func (*Client) GetPackage ¶
GetPackage fetches a single dataset by name/slug and returns the summary record plus all resource records.
func (*Client) ListOrganizations ¶
ListOrganizations returns HDX organizations.
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) 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.
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.