Documentation
¶
Overview ¶
Package catapi is the library behind the catapi command line: the HTTP client, request shaping, and typed data models for TheCatAPI.
The free tier at api.thecatapi.com requires no API key. The Client sets a polite User-Agent, paces requests, and retries transient failures (429 and 5xx) with a capped backoff.
Index ¶
- Constants
- type Breed
- type Category
- type Client
- func (c *Client) Breeds(ctx context.Context, limit, page int) ([]Breed, error)
- func (c *Client) Categories(ctx context.Context) ([]Category, error)
- func (c *Client) Search(ctx context.Context, limit int, breed string, hasBreeds bool) ([]Image, error)
- func (c *Client) SearchBreeds(ctx context.Context, query string) ([]Breed, error)
- type Config
- type Domain
- type Image
Constants ¶
const Host = "api.thecatapi.com"
Host is the site this client talks to.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Breed ¶ added in v0.2.0
type Breed struct {
ID string `kit:"id" json:"id"`
Name string `json:"name"`
Origin string `json:"origin"`
Temperament string `json:"temperament"`
LifeSpan string `json:"life_span"`
Description string `json:"description"`
}
Breed is one cat breed from TheCatAPI.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to TheCatAPI over HTTP.
func (*Client) Breeds ¶ added in v0.2.0
Breeds returns all cat breeds paginated. limit and page are passed directly to the API. Calls GET /v1/breeds.
func (*Client) Categories ¶ added in v0.2.0
Categories returns all image categories. Calls GET /v1/categories.
func (*Client) Search ¶ added in v0.2.0
func (c *Client) Search(ctx context.Context, limit int, breed string, hasBreeds bool) ([]Image, error)
Search returns cat images. Use breed to filter by breed ID (e.g. "beng"). Set hasBreeds to true to only return images that have breed info attached. limit controls the maximum number of results (default 5 if <= 0). Calls GET /v1/images/search.
type Config ¶ added in v0.2.0
type Config struct {
BaseURL string
UserAgent string
Rate time.Duration
Timeout time.Duration
Retries int
}
Config holds all tunable parameters for the Client.
func DefaultConfig ¶ added in v0.2.0
func DefaultConfig() Config
DefaultConfig returns a Config with sensible defaults for the free API tier.
type Domain ¶
type Domain struct{}
Domain is the catapi driver.
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 Image ¶ added in v0.2.0
type Image struct {
ID string `kit:"id" json:"id"`
URL string `json:"url"`
Width int `json:"width"`
Height int `json:"height"`
Breed string `json:"breed"` // first breed name, or ""
Origin string `json:"origin"` // first breed origin, or ""
}
Image is one cat image result from TheCatAPI.