Documentation
¶
Overview ¶
Package thecatapi is the library behind the thecatapi command line: the HTTP client, request shaping, and the typed data models for The Cat API.
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
- type Breed
- type Client
- func (c *Client) Get(ctx context.Context, url string) ([]byte, error)
- func (c *Client) GetBreed(ctx context.Context, id string) (*Breed, error)
- func (c *Client) GetImage(ctx context.Context, id string) (*Image, error)
- func (c *Client) ListBreeds(ctx context.Context, limit int) ([]*Breed, error)
- func (c *Client) ListImages(ctx context.Context, limit int, breedID string) ([]*Image, error)
- func (c *Client) SearchBreeds(ctx context.Context, query string) ([]*Breed, error)
- type Domain
- type Image
Constants ¶
const BaseURL = "https://" + Host
BaseURL is the root every request is built from.
const DefaultUserAgent = "thecatapi-cli/dev (+https://github.com/tamnd/thecatapi-cli)"
DefaultUserAgent identifies the client to The Cat API.
const Host = "api.thecatapi.com"
Host is the API host this client talks to.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Breed ¶
type Breed struct {
ID string `kit:"id" json:"id"`
Name string `json:"name"`
Origin string `json:"origin"`
Description string `json:"description"`
Temperament string `json:"temperament"`
LifeSpan string `json:"life_span"`
WeightMetric string `json:"weight_metric"`
Indoor int `json:"indoor"`
Adaptability int `json:"adaptability"`
Intelligence int `json:"intelligence"`
EnergyLevel int `json:"energy_level"`
Affection int `json:"affection_level"`
WikipediaURL string `json:"wikipedia_url"`
}
Breed represents a cat breed from The Cat API.
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 Cat 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 five retries on transient errors.
func (*Client) ListBreeds ¶
ListBreeds returns up to limit breeds from the API.
func (*Client) ListImages ¶
ListImages returns up to limit cat images, optionally filtered by breed ID.
type Domain ¶
type Domain struct{}
Domain is the thecatapi driver.
func (Domain) Classify ¶
Classify turns any accepted input into the canonical (type, id). Short breed-like IDs (4 chars, lowercase letters) are classified as "breed"; everything else is classified as "query".
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.