Documentation
¶
Overview ¶
Package openlibrary is the library behind the openlibrary command line: the HTTP client, request shaping, and the typed data models for Open Library.
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) GetBookByISBN(ctx context.Context, isbn string) (*Book, error)
- func (c *Client) GetEditions(ctx context.Context, olid string, limit int) ([]Edition, error)
- func (c *Client) GetWork(ctx context.Context, olid string) (*Work, error)
- func (c *Client) SearchAuthors(ctx context.Context, query string, limit int) ([]Author, error)
- func (c *Client) SearchBooks(ctx context.Context, query string, limit int) ([]Book, error)
- type Config
- type Domain
- type Edition
- type Work
Constants ¶
const BaseURL = "https://" + Host
BaseURL is the root every request is built from.
const DefaultUserAgent = "openlibrary-cli/0.1 (tamnd87@gmail.com)"
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"`
}
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"` // comma-joined author names
FirstPublishYear int `json:"first_publish_year"`
ISBN string `json:"isbn"` // first ISBN if any
Subjects string `json:"subjects"` // comma-joined first 3 subjects
Pages int `json:"pages"` // number_of_pages_median (search) or number_of_pages (isbn)
}
Book is a search result or ISBN lookup 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. "OL34184A"). The /authors/ prefix is stripped from olid if present.
func (*Client) GetBookByISBN ¶ added in v0.1.2
GetBookByISBN fetches a book by ISBN using the /api/books endpoint. The isbn argument may contain hyphens; they are stripped automatically.
func (*Client) GetEditions ¶ added in v0.1.4
GetEditions fetches the editions list for a work by OL ID (e.g. "OL45804W").
func (*Client) GetWork ¶ added in v0.1.1
GetWork fetches the full work record by OL ID (e.g. "OL45804W"). The /works/ prefix is stripped from olid if present.
func (*Client) SearchAuthors ¶ added in v0.1.1
SearchAuthors searches Open Library for authors matching query.
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 OL34184A) -> ("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"`
Publisher string `json:"publisher"` // first publisher
Published string `json:"published"`
ISBN13 string `json:"isbn_13"` // first isbn_13
}
Edition is one edition entry from /works/{key}/editions.json.
type Work ¶ added in v0.1.1
type Work struct {
Key string `kit:"id" json:"key"`
Title string `json:"title"`
Description string `json:"description"`
Subjects string `json:"subjects"` // comma-joined first 5 subjects
FirstPublish string `json:"first_publish"`
}
Work is a full work record from /works/{key}.json.