Documentation
¶
Overview ¶
Package openlibrary is the library behind the openlibrary command line: the HTTP client, request shaping, and the typed data models for openlibrary.
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 site throws under load.
Index ¶
- Constants
- type Author
- type Book
- type Client
- func (c *Client) GetAuthor(ctx context.Context, olid string) (*Author, error)
- func (c *Client) GetAuthorWorks(ctx context.Context, olid string, limit int) ([]SubjectWork, error)
- func (c *Client) GetEditionByISBN(ctx context.Context, isbn string) (*Edition, error)
- func (c *Client) GetSubject(ctx context.Context, subject string, limit int) ([]SubjectWork, error)
- func (c *Client) GetWork(ctx context.Context, olid string) (*Work, error)
- func (c *Client) SearchBooks(ctx context.Context, query string, limit int) ([]Book, error)
- type Config
- type Domain
- type Edition
- type SubjectWork
- type Work
Constants ¶
const BaseURL = "https://" + Host
BaseURL is the root every request is built from.
const DefaultUserAgent = "Mozilla/5.0 (compatible; openlibrary-cli/dev; +https://github.com/tamnd/openlibrary-cli)"
DefaultUserAgent identifies the client to Open Library.
const Host = "openlibrary.org"
Host is the site this client talks to.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Author ¶ added in v0.1.1
type Author struct {
Key string `kit:"id" json:"key"`
Name string `json:"name"`
BirthDate string `json:"birth_date"`
DeathDate string `json:"death_date"`
Bio string `json:"bio"`
WorkCount int `json:"work_count"`
}
Author is an author record from /authors/{key}.json.
type Book ¶
type Book struct {
Key string `kit:"id" json:"key"`
Title string `json:"title"`
Authors []string `json:"authors"`
PublishYear int `json:"first_publish_year"`
ISBN []string `json:"isbn"`
}
Book is a search result record from Open Library.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to Open Library over HTTP.
func (*Client) GetAuthor ¶ added in v0.1.1
GetAuthor fetches the full author record by OL ID (e.g. "OL26320A"). The /authors/ prefix is stripped from olid if present.
func (*Client) GetAuthorWorks ¶ added in v0.1.3
GetAuthorWorks fetches the works list for an author by OL ID.
func (*Client) GetEditionByISBN ¶ added in v0.1.3
GetEditionByISBN fetches a book edition by ISBN (10 or 13 digits).
func (*Client) GetSubject ¶ added in v0.1.3
GetSubject fetches the works under a subject category.
type Config ¶
type Config struct {
BaseURL string
UserAgent string
Rate time.Duration
Timeout time.Duration
Retries int
}
Config holds all tunable client parameters.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns sensible defaults for a polite CLI client.
type Domain ¶
type Domain struct{}
Domain is the openlibrary driver. It carries no state; the per-run client is built by the factory Register hands kit.
func (Domain) Classify ¶
Classify turns any accepted input into the canonical (type, id).
- starts with "OL" and ends in "A" (like OL26320A) → ("author", input)
- starts with "OL" and ends in "W" (like OL45804W) → ("work", input)
- all digits, 10 or 13 chars → ("isbn", input)
- otherwise → ("query", input)
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 Edition ¶ added in v0.1.3
type Edition struct {
Key string `kit:"id" json:"key"`
Title string `json:"title"`
Publishers []string `json:"publishers"`
PublishDate string `json:"publish_date"`
Pages int `json:"pages"`
ISBN10 []string `json:"isbn_10"`
ISBN13 []string `json:"isbn_13"`
}
Edition is a book edition record from /isbn/{isbn}.json.
type SubjectWork ¶ added in v0.1.3
type SubjectWork struct {
Key string `kit:"id" json:"key"`
Title string `json:"title"`
Authors []string `json:"authors"`
}
SubjectWork is one work entry from a subject listing.