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) 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)
- func (c *Client) Subject(ctx context.Context, subject string, limit int) ([]Book, error)
- type Config
- type Domain
- type Subject
- 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 {
Rank int `json:"rank" csv:"rank" tsv:"rank"`
Key string `json:"key" csv:"key" tsv:"key"`
Name string `json:"name" csv:"name" tsv:"name"`
BirthDate string `json:"birth_date" csv:"birth_date" tsv:"birth_date"`
DeathDate string `json:"death_date" csv:"death_date" tsv:"death_date"`
WorkCount int `json:"work_count" csv:"work_count" tsv:"work_count"`
TopWork string `json:"top_work" csv:"top_work" tsv:"top_work"`
URL string `json:"url" csv:"url" tsv:"url"`
}
Author is one author record from Open Library.
type Book ¶
type Book struct {
Rank int `json:"rank" csv:"rank" tsv:"rank"`
Key string `json:"key" csv:"key" tsv:"key"`
Title string `json:"title" csv:"title" tsv:"title"`
Authors []string `json:"authors" csv:"authors" tsv:"authors"`
FirstYear int `json:"first_publish_year" csv:"first_publish_year" tsv:"first_publish_year"`
Editions int `json:"edition_count" csv:"edition_count" tsv:"edition_count"`
EbookAccess string `json:"ebook_access" csv:"ebook_access" tsv:"ebook_access"`
Languages []string `json:"languages" csv:"languages" tsv:"languages"`
CoverID int `json:"cover_id" csv:"cover_id" tsv:"cover_id"`
URL string `json:"url" csv:"url" tsv:"url"`
}
Book is one book 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. "OL23919A"). The /authors/ prefix is stripped from olid if present.
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.
func (*Client) SearchBooks ¶
SearchBooks searches Open Library for books 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) 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 Subject ¶
type Subject struct {
Rank int `json:"rank" csv:"rank" tsv:"rank"`
Name string `json:"name" csv:"name" tsv:"name"`
WorkCount int `json:"work_count" csv:"work_count" tsv:"work_count"`
URL string `json:"url" csv:"url" tsv:"url"`
}
Subject is a subject category with its book count.
type Work ¶ added in v0.1.1
type Work struct {
Key string `json:"key" csv:"key" tsv:"key"`
Title string `json:"title" csv:"title" tsv:"title"`
Desc string `json:"description" csv:"description" tsv:"description"`
Subjects []string `json:"subjects" csv:"subjects" tsv:"subjects"`
AuthorKeys []string `json:"author_keys" csv:"author_keys" tsv:"author_keys"`
URL string `json:"url" csv:"url" tsv:"url"`
}
Work is one work/book record from the /works/{OLID}.json endpoint.