goodreads

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: MIT Imports: 22 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 (
	DefaultClient = &Client{
		client:       http.DefaultClient,
		goodreadsUrl: utils.CloneURL(defaultGoodreadsUrl),
		apiKey:       DefaultAPIKey,
	}

	BookSearchTypeTitle  = bookSearchTypeEnum.Add(BookSearchType{"title"})
	BookSearchTypeAuthor = bookSearchTypeEnum.Add(BookSearchType{"author"})
	BookSearchTypes      = bookSearchTypeEnum.Enum()
)

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"`
	Title  string `xml:"title"`
	Author string `xml:"author>name"`
}

func (*BookOverview) Sanitise

func (b *BookOverview) Sanitise()

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, bookTitle string, bookAuthor *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, bookTitle string, bookAuthor *string) ([]Book, error)

SearchBooks search for a book by its title and optionally an author (which can give better results) 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"`
	Title            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  string  `xml:"publication_year"`
	PublicationMonth string  `xml:"publication_month"`
	PublicationDay   string  `xml:"publication_day"`
	Publisher        string  `xml:"publisher"`
	CountryCode      string  `xml:"country_code"`
	Language         string  `xml:"language_code"`
}

func (*Edition) Sanitise

func (e *Edition) Sanitise()

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 {
	Title         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

Jump to

Keyboard shortcuts

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