sbdi

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: 11 Imported by: 0

Documentation

Overview

Package sbdi is the library behind the sbdi command line: the HTTP client, request shaping, and the typed data models for the Swedish Biodiversity Data Infrastructure (SBDI).

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. Build your endpoint calls and JSON decoding on top of it.

Index

Constants

View Source
const BaseURL = "https://records.biodiversitydata.se/ws"

BaseURL is the root every request is built from.

View Source
const Host = "records.biodiversitydata.se"

Host is the site this client talks to, and the host the URI driver in domain.go claims.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client talks to SBDI over HTTP.

func NewClient

func NewClient() *Client

NewClient returns a Client with sensible defaults.

func NewClientAt

func NewClientAt(baseURL string) *Client

NewClientAt returns a Client pointed at baseURL instead of the live API. Intended for tests.

func (*Client) SearchAt

func (c *Client) SearchAt(ctx context.Context, baseURL, query string, limit, offset int) ([]*Occurrence, int, error)

SearchAt is like SearchOccurrences but uses baseURL instead of the configured one. Intended for tests.

func (*Client) SearchOccurrences

func (c *Client) SearchOccurrences(ctx context.Context, query string, limit, offset int) ([]*Occurrence, int, error)

SearchOccurrences queries /occurrences/search and returns matching occurrences plus the total count.

type Config

type Config struct {
	BaseURL   string
	Rate      time.Duration
	Retries   int
	Timeout   time.Duration
	UserAgent string
}

Config holds all tunable parameters for a Client.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a Config with sensible defaults.

type Domain

type Domain struct{}

Domain is the sbdi 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) (string, string, error)

Classify turns any accepted input into the canonical (type, id). Any non-empty string is treated as an occurrence 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 is the inverse: 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 Occurrence

type Occurrence struct {
	ID             string  `json:"id"                       kit:"id"` // = uuid
	OccurrenceID   string  `json:"occurrence_id,omitempty"`
	ScientificName string  `json:"scientific_name,omitempty"`
	VernacularName string  `json:"vernacular_name,omitempty"`
	TaxonRank      string  `json:"taxon_rank,omitempty"`
	Kingdom        string  `json:"kingdom,omitempty"`
	Family         string  `json:"family,omitempty"`
	EventDate      string  `json:"event_date,omitempty"`
	Year           int     `json:"year,omitempty"`
	BasisOfRecord  string  `json:"basis_of_record,omitempty"`
	DataResource   string  `json:"data_resource,omitempty"`
	Institution    string  `json:"institution,omitempty"`
	Country        string  `json:"country,omitempty"`
	StateProvince  string  `json:"state_province,omitempty"`
	Latitude       float64 `json:"latitude,omitempty"`
	Longitude      float64 `json:"longitude,omitempty"`
	License        string  `json:"license,omitempty"`
	Collector      string  `json:"collector,omitempty"`
}

Occurrence is the public record type: one biodiversity observation from SBDI.

Jump to

Keyboard shortcuts

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