goodreads

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2024 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultGoodreadsUrl = "https://www.goodreads.com"
	DefaultAPIKey       = "ckvsiSDsuqh7omh74ZZ6Q" // Read only API key kindly provided by LazyLibrarian
)

Variables

View Source
var (
	BookSearchTypeTitle  = bookSearchTypeEnum.Add(BookSearchType{"title"})
	BookSearchTypeAuthor = bookSearchTypeEnum.Add(BookSearchType{"author"})
	BookSearchTypeAll    = bookSearchTypeEnum.Add(BookSearchType{"all"})

	BookSearchTypes = bookSearchTypeEnum.Enum()
)
View Source
var (
	DefaultClient = &Client{
		client:       http.DefaultClient,
		goodreadsUrl: utils.CloneURL(defaultGoodreadsUrl),
		apiKey:       DefaultAPIKey,
	}
)

Functions

func BookIds

func BookIds(books []BookOverview) []string

func BookTitles

func BookTitles(books []BookOverview) []string

Types

type AuthorDetails

type AuthorDetails struct {
	Role             string `xml:"role"`
	ImageURL         string `xml:"image_url"`
	SmallImageURL    string `xml:"small_image_url"`
	Link             string `xml:"link"`
	AverageRating    string `xml:"average_rating"`
	RatingsCount     string `xml:"ratings_count"`
	TextReviewsCount string `xml:"text_reviews_count"`
	// contains filtered or unexported fields
}

type AuthorSummary

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

type Book

type Book struct {
	Work        Work            `xml:"work"`
	BestEdition Edition         // Unmarshalled using the custom unmarshaler below
	Authors     []AuthorDetails `xml:"authors>author"`
	Series      []SeriesBook    `xml:"series_works>series_work"`
	Genres      Genres          `xml:"popular_shelves"` // The first "genre" shelves
}

func (*Book) Sanitise

func (b *Book) Sanitise()

func (*Book) UnmarshalXML

func (b *Book) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

type BookOverview

type BookOverview struct {
	Id        string `xml:"id"`
	FullTitle string `xml:"title"`
	Author    string `xml:"author>name"`
}

func (BookOverview) Subtitle added in v0.2.0

func (o BookOverview) Subtitle() string

Subtitle is the subtitle part of the full title with any series removed.

func (BookOverview) Title

func (o BookOverview) Title() string

Title is the full title with any subtitle and series removed.

type BookSearchType

type BookSearchType enum.Member[string]

type Client

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

func NewClient

func NewClient(client *http.Client, goodreadsUrl, apiKey *string) (*Client, error)

NewClient creates a new goodreads client. If client is nil, the default http client will be used. If goodreads url is nil or unset, the default goodreads url will be used. Will return an error if the goodreads url is invalid.

func (*Client) GetBookById

func (c *Client) GetBookById(ctx context.Context, bookId string) (Book, error)

GetBookById gets a book by its id. https://www.goodreads.com/api/index#book.show

func (*Client) GetBookByTitle

func (c *Client) GetBookByTitle(ctx context.Context, title string, author *string) (Book, error)

GetBookByTitle gets a book by its title and optionally an author (which can give a better match) https://www.goodreads.com/api/index#book.title

func (*Client) GetBooksByIds

func (c *Client) GetBooksByIds(ctx context.Context, bookIds []string) ([]Book, error)

func (*Client) SearchBooks

func (c *Client) SearchBooks(ctx context.Context, title string, author *string) ([]Book, error)

SearchBooks search for a book by its title and optionally an author (which can give better ordered results). Returns the first 10 pages of books. See: https://www.goodreads.com/api/index#search.books

func (*Client) URL

func (c *Client) URL() *url.URL

URL returns a clone of of the amazon url used by the client

type Edition

type Edition struct {
	Id               string  `xml:"id"`
	ISBN             *string `xml:"isbn13"`
	FullTitle        string  `xml:"title"`
	Description      string  `xml:"description"`
	NumPages         string  `xml:"num_pages"`
	ImageURL         string  `xml:"image_url"`
	URL              string  `xml:"url"`
	Format           string  `xml:"format"`
	PublicationYear  int     `xml:"publication_year"`
	PublicationMonth int     `xml:"publication_month"`
	PublicationDay   int     `xml:"publication_day"`
	Publisher        string  `xml:"publisher"`
	CountryCode      string  `xml:"country_code"`
	Language         string  `xml:"language_code"`
}

func (*Edition) Sanitise

func (e *Edition) Sanitise()

func (Edition) Subtitle added in v0.2.0

func (e Edition) Subtitle() string

Subtitle is the subtitle part of the full title with any series removed.

func (Edition) Title

func (e Edition) Title() string

Title is the full title with any subtitle and series removed.

type Genres

type Genres []string

func (*Genres) UnmarshalXML

func (g *Genres) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

type Series

type Series struct {
	Id               string `xml:"id"`
	Title            string `xml:"title"`
	Description      string `xml:"description"`
	PrimaryBookCount int    `xml:"primary_work_count"`
	TotalBookCount   int    `xml:"series_works_count"`
	Numbered         bool   `xml:"numbered"`
}

func (*Series) Sanitise

func (s *Series) Sanitise()

type SeriesBook

type SeriesBook struct {
	Series       Series  `xml:"series"`
	BookPosition *string `xml:"user_position"`
}

func (*SeriesBook) Sanitise

func (s *SeriesBook) Sanitise()

type Work

type Work struct {
	FullTitle     string `xml:"original_title"`
	MediaType     string `xml:"media_type"`
	EditionsCount int    `xml:"books_count"`

	// Publication
	PublicationYear  int `xml:"original_publication_year"`
	PublicationMonth int `xml:"original_publication_month"`
	PublicationDay   int `xml:"original_publication_day"`

	// Ratings
	RatingsSum         int    `xml:"ratings_sum"`
	RatingsCount       int    `xml:"ratings_count"`
	ReviewsCount       int    `xml:"text_reviews_count"`
	RatingDistribution string `xml:"rating_dist"`
}

func (Work) AverageRating

func (w Work) AverageRating() float64

func (Work) Subtitle added in v0.2.0

func (w Work) Subtitle() string

Subtitle is the subtitle part of the full title with any series removed.

func (Work) Title

func (w Work) Title() string

Title is the full title with any subtitle and series removed.

Jump to

Keyboard shortcuts

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