metmuseum

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package metmuseum is the library behind the metmuseum command line: the HTTP client, request shaping, and typed data models for the Metropolitan Museum of Art public Collection API (https://collectionapi.metmuseum.org/public/collection/v1).

No API key is required. The Client paces requests, sets a real User-Agent, and retries transient failures (429 and 5xx).

Index

Constants

View Source
const BaseURL = "https://" + Host + "/public/collection/v1"

BaseURL is the root every API request is built from.

View Source
const DefaultUserAgent = "metmuseum-cli/0.1.0 (github.com/tamnd/metmuseum-cli)"

DefaultUserAgent identifies the client to the Met Museum API.

View Source
const Host = "collectionapi.metmuseum.org"

Host is the API hostname.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client talks to the Metropolitan Museum of Art API.

func NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client with the given configuration.

func (*Client) GetObject

func (c *Client) GetObject(ctx context.Context, id int) (*Object, error)

GetObject fetches a single museum object by numeric ID.

func (*Client) ListDepartments

func (c *Client) ListDepartments(ctx context.Context) ([]Department, error)

ListDepartments lists all museum departments.

func (*Client) SearchObjects

func (c *Client) SearchObjects(ctx context.Context, q string, hasImages, publicDomain bool, deptID, limit int) ([]Object, error)

SearchObjects searches objects and fetches full details for the top results. It calls /search first, then fans out to /objects/{id} for each ID up to limit.

type Config

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

func DefaultConfig() Config

DefaultConfig returns a Config with sensible defaults.

type Department

type Department struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

Department holds museum department data.

type Domain

type Domain struct{}

Domain is the metmuseum driver.

func (Domain) Classify

func (Domain) Classify(input string) (string, string, error)

Classify turns a URL or ID into (type, id).

func (Domain) Info

func (Domain) Info() kit.DomainInfo

Info describes the scheme, hostnames, and binary identity.

func (Domain) Locate

func (Domain) Locate(t, 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 operation onto app.

type Object

type Object struct {
	ID                int    `json:"id"`
	Title             string `json:"title"`
	Artist            string `json:"artist"`
	Nationality       string `json:"nationality,omitempty"`
	Date              string `json:"date,omitempty"`
	Medium            string `json:"medium,omitempty"`
	Dimensions        string `json:"dimensions,omitempty"`
	Department        string `json:"department,omitempty"`
	PublicDomain      bool   `json:"public_domain"`
	PrimaryImageSmall string `json:"primary_image_small,omitempty"`
	URL               string `json:"url,omitempty"`
}

Object holds the public data about a single museum object.

type SearchResult

type SearchResult struct {
	Total     int   `json:"total"`
	ObjectIDs []int `json:"object_ids"`
}

SearchResult holds raw search results (IDs only).

Jump to

Keyboard shortcuts

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