openlibrary

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: 10 Imported by: 0

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

View Source
const BaseURL = "https://" + Host

BaseURL is the root every request is built from.

View Source
const DefaultUserAgent = "Mozilla/5.0 (compatible; openlibrary-cli/dev; +https://github.com/tamnd/openlibrary-cli)"

DefaultUserAgent identifies the client to Open Library.

View Source
const Host = "openlibrary.org"

Host is the site this client talks to.

Variables

This section is empty.

Functions

This section is empty.

Types

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 NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client using cfg.

func (*Client) SearchBooks

func (c *Client) SearchBooks(ctx context.Context, query string, limit int) ([]Book, error)

SearchBooks searches Open Library for books matching query.

func (*Client) Subject

func (c *Client) Subject(ctx context.Context, subject string, limit int) ([]Book, error)

Subject returns the books under a subject category. subject may contain spaces; they are converted to underscores.

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

func (Domain) Classify(input string) (uriType, id string, err error)

Classify turns any accepted input into the canonical (type, id).

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.

func (Domain) Locate

func (Domain) Locate(uriType, id string) (string, error)

Locate is the inverse: 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 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.

Jump to

Keyboard shortcuts

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