obis

package
v0.1.0 Latest Latest
Warning

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

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

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

View Source
const BaseURL = "https://" + Host + "/v3"

BaseURL is the API root every request is built from.

View Source
const DefaultUserAgent = "obis/dev (+https://github.com/tamnd/obis-cli)"

DefaultUserAgent identifies the client to OBIS.

View Source
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

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

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) GetStats

func (c *Client) GetStats(ctx context.Context) (*Stats, error)

GetStats returns the global OBIS statistics snapshot.

func (*Client) GetTaxon

func (c *Client) GetTaxon(ctx context.Context, scientificName string) ([]*Taxon, error)

GetTaxon looks up taxonomic information for a species by scientific name.

func (*Client) ListDatasets

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

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

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

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.

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 OBIS operation onto app.

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.

Jump to

Keyboard shortcuts

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