Documentation
¶
Overview ¶
Package obis is the library behind the obis command line: the HTTP client, request shaping, and the typed data models for the Ocean Biodiversity Information System (OBIS) API at api.obis.org/v3.
The Client here is the spine every command shares. It sets a real User-Agent, paces requests so a busy session stays polite, and retries the transient failures (429 and 5xx) that any public API throws under load.
Index ¶
- Constants
- type Client
- func (c *Client) Get(ctx context.Context, url string) ([]byte, error)
- func (c *Client) GetStats(ctx context.Context) (*Stats, error)
- func (c *Client) GetTaxon(ctx context.Context, scientificName string) ([]*Taxon, error)
- func (c *Client) ListDatasets(ctx context.Context, limit int) ([]*Dataset, int, error)
- func (c *Client) SearchOccurrences(ctx context.Context, scientificName string, limit int) ([]*Occurrence, int, error)
- type Dataset
- type Domain
- type Occurrence
- type Stats
- type Taxon
Constants ¶
const BaseURL = "https://" + Host + "/v3"
BaseURL is the API root every request is built from.
const DefaultUserAgent = "obis/dev (+https://github.com/tamnd/obis-cli)"
DefaultUserAgent identifies the client to OBIS.
const Host = "api.obis.org"
Host is the API host this client talks to.
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. Zero means no pacing.
Rate time.Duration
Retries int
// contains filtered or unexported fields
}
Client talks to the OBIS API over HTTP.
func NewClient ¶
func NewClient() *Client
NewClient returns a Client with sensible defaults: a 30s timeout, a 300ms minimum gap between requests, and three retries on transient errors.
func (*Client) Get ¶
Get fetches url and returns the response body. It paces and retries according to the client's settings. The caller owns nothing extra; the body is read fully and closed here.
func (*Client) ListDatasets ¶
ListDatasets lists contributing datasets in OBIS, up to limit records. It returns the datasets and the total dataset count.
func (*Client) SearchOccurrences ¶
func (c *Client) SearchOccurrences(ctx context.Context, scientificName string, limit int) ([]*Occurrence, int, error)
SearchOccurrences searches for species occurrence records by scientific name. It returns up to limit records and the total count of matching records.
type Dataset ¶
type Dataset struct {
ID string `json:"id" kit:"id"`
Title string `json:"title"`
URL string `json:"url,omitempty"`
}
Dataset is a contributing data source in OBIS.
type Domain ¶
type Domain struct{}
Domain is the OBIS driver. It carries no state; the per-run client is built by the factory Register hands kit.
func (Domain) Classify ¶
Classify turns any accepted input into (type, id). Any non-empty string maps to ("occurrence", input) so it is addressable as a resource URI.
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 Occurrence ¶
type Occurrence struct {
ID string `json:"id" kit:"id"`
ScientificName string `json:"scientific_name"`
Class string `json:"class,omitempty"`
Family string `json:"family,omitempty"`
Genus string `json:"genus,omitempty"`
Latitude float64 `json:"latitude,omitempty"`
Longitude float64 `json:"longitude,omitempty"`
Depth float64 `json:"depth,omitempty"`
Year int `json:"year,omitempty"`
Country string `json:"country,omitempty"`
Dataset string `json:"dataset,omitempty"`
BasisOfRecord string `json:"basis_of_record,omitempty"`
}
Occurrence is a single species sighting record from OBIS.
type Stats ¶
type Stats struct {
Records int `json:"records"`
Species int `json:"species"`
Taxa int `json:"taxa"`
Datasets int `json:"datasets"`
}
Stats holds the global OBIS statistics snapshot.
type Taxon ¶
type Taxon struct {
ID string `json:"id" kit:"id"`
ScientificName string `json:"scientific_name"`
Rank string `json:"rank,omitempty"`
Kingdom string `json:"kingdom,omitempty"`
Phylum string `json:"phylum,omitempty"`
Class string `json:"class,omitempty"`
Order string `json:"order,omitempty"`
Family string `json:"family,omitempty"`
}
Taxon is a taxonomic classification record from OBIS.