gol

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2021 License: MIT Imports: 9 Imported by: 1

README

Gol

This is still WIP

gol (Golang Open Library) is an interface for the OpenLibrary API. For more information about the API itself please visit openlibrary.org.

Go Reference go

As OpenLibrary's data is always changing, under the hood all the JSON data is handled through `gabs`. Subsequently if a field is not accessible with a method, gabs's container can be used instead from any struct.

Functions

For more information, browse the docs folder where you can find additional about every API and its subsequent methods.

Documentation

Overview

Package gol implements an easy interface to make calls to the OpenLibrary API

gol uses the WorkAPI, the EditionAPI, and the CoverAPI

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cover

func Cover(c HasCovers, size string) string

func GetAuthorCoverURL

func GetAuthorCoverURL(key string, value string, size string) string

GetAuthorCoverURL returns the url of author cover (picture) from an identifier. The size can be specified (S, M, or L)

func GetBookCoverURL

func GetBookCoverURL(key string, value string, size string) string

GetBookCoverURL returns the url to book cover from an identifier. The size can be specified (S, M, or L)

func GetCoverURL

func GetCoverURL(coverType string, key string, value string, size string) string

GetCoverURL returns the url of the requested cover GetCoverURL accepts the cover type i.e b(book), a(author), the key of the book i.e ISBN, OCLC, LCCN, OLID and ID, the value of the key, and the size of the cover (S, M, or L)

func HasError

func HasError(data Container) error

Types

type Author

type Author struct {
	Container

	Key string
	// contains filtered or unexported fields
}

func Authors

func Authors(i IKeyAuthors) (as []Author, err error)

func GetAuthor

func GetAuthor(id string) (a Author, err error)

GetAuthor returns an Author struct

func (Author) Cover

func (a Author) Cover(size string) string

Cover returns (if it exists) the URL of the first Author's Photo/Cover

func (Author) FirstCoverKey

func (a Author) FirstCoverKey() string

func (*Author) KeyCovers

func (a *Author) KeyCovers() ([]string, error)

KeyCovers returns (if they exists) the key covers/photo of the author

func (*Author) Works

func (a *Author) Works() ([]Work, error)

works returns all the works of the author

type Book

type Book struct {
	Container
	// contains filtered or unexported fields
}

func GetEdition

func GetEdition(olid string) (b Book, err error)

GetEdition returns a book from its open library id

func GetEditionISBN

func GetEditionISBN(isbnid string) (b Book, err error)

GetEditionISBN returns a book from its isbnid

func (Book) Authors

func (b Book) Authors() ([]Author, error)

Authors returns the authors of the book

func (Book) Cover

func (b Book) Cover(size string) string

Cover returns (if it exists) the URL of the Book's Cover

func (Book) FirstCoverKey

func (b Book) FirstCoverKey() string

FirstCoverKey returns the first cover if it exists

func (Book) GoodReads

func (b Book) GoodReads() (string, error)

GoodReads returns the goodreads identifier

func (*Book) Isbn10

func (b *Book) Isbn10() (string, error)

Isbn10 returns the isbn10 identifier

func (*Book) KeyAuthors

func (b *Book) KeyAuthors() ([]string, error)

KeyAuthors returns array of all authors keys

func (*Book) KeyCovers

func (b *Book) KeyCovers() ([]string, error)

KeyCover returns (if it exists) the ID of the work's cover

func (*Book) Load

func (b *Book) Load()

Load tries to load the fields from the json container

func (*Book) NumberOfPages

func (b *Book) NumberOfPages() (int, error)

func (*Book) Publishers

func (b *Book) Publishers() ([]string, error)

returns the publishers of the book

func (*Book) Subjects

func (b *Book) Subjects() ([]string, error)

Subjects returns the subjects of the book

func (*Book) Title

func (b *Book) Title() (string, error)

func (*Book) WorkKeys

func (b *Book) WorkKeys() ([]string, error)

type Container

type Container = *gabs.Container

func MakeAuthorRequest

func MakeAuthorRequest(id string) (Container, error)

func MakeBookRequest

func MakeBookRequest(id string) (Container, error)

func MakeDetailedSubjectRequest

func MakeDetailedSubjectRequest(subject string) (Container, error)

func MakeISBNRequest

func MakeISBNRequest(isbn string) (Container, error)

func MakeRequest

func MakeRequest(api string, id string, params ...string) (Container, error)

func MakeSubjectRequest

func MakeSubjectRequest(subject string) (Container, error)

func MakeWorkRequest

func MakeWorkRequest(work string) (Container, error)

func Query

func Query(url string) (Container, error)

Query returns the result of the query from a url -- Constructed by Construct()

func Request

func Request(url string) (Container, error)
func Search(s string) (Container, error)

Search returns search API data from a constructed url

type HasCovers

type HasCovers interface {
	FirstCoverKey() string
}

type IKeyAuthors

type IKeyAuthors interface {
	KeyAuthors() ([]string, error)
}

type QueryURL

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

func QueryUrl

func QueryUrl() QueryURL

QueryURL returns QueryURL type that holds OpenLibrary Query URL

func (QueryURL) Author

func (q QueryURL) Author(author string) QueryURL

Author returns a QueryURL with the author that has be passed as an arg

func (QueryURL) Construct

func (q QueryURL) Construct() string

Construct returns the string represtation of the QueryURL

func (QueryURL) Limit

func (q QueryURL) Limit(l int) QueryURL

Limit sets the number limit of the Query

func (QueryURL) Title

func (q QueryURL) Title(t string) QueryURL

Title sets the title key of the query

func (QueryURL) Type

func (q QueryURL) Type(s string) QueryURL

Type returns a QueryURL with the type that has be passed as an arg

func (QueryURL) Work

func (q QueryURL) Work(w string) QueryURL

Work sets the work key of the Query

type SearchURL

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

SearchURL holds information about the Search URL

func SearchUrl

func SearchUrl() SearchURL

Url returns OpenLibrary's search url

func (SearchURL) All

func (s SearchURL) All(q string) SearchURL

All allows to search in everything

func (SearchURL) Author

func (s SearchURL) Author(a string) SearchURL

Author allows to only search in authors

func (SearchURL) Construct

func (su SearchURL) Construct() string

Construct contructs and returns a complete searchable url

func (SearchURL) Subject

func (s SearchURL) Subject(sbj string) SearchURL

Subject allow to search in a specific subject

func (SearchURL) Title

func (s SearchURL) Title(t string) SearchURL

Title allows to only search in titles

type Subject

type Subject struct {
	Container
	// contains filtered or unexported fields
}

func GetSubject

func GetSubject(subject string) (sbj Subject, err error)

GetSubject returns the chosen subject's information

func GetSubjectDetails

func GetSubjectDetails(subject string) (sbj Subject, err error)

GetSubject returns the chosen subject's information with more details

func (*Subject) Works

func (sbj *Subject) Works() ([]Work, error)

Works returns the works related to that subject. Note that the work fields won't get loaded (using the Work.load() method); If the works were loaded before, it will return sbj.works

type Work

type Work struct {
	Container

	NumberOfEditions int
	// contains filtered or unexported fields
}

func GetWork

func GetWork(id string) (w Work, err error)

GetWork returns the work from the workID After making the request, the fields are loaded with Load

func (Work) Authors

func (w Work) Authors() (a []Author, err error)

Authors returns more information about the authors (using AuthorsKey)

func (Work) Cover

func (w Work) Cover(size string) string

Cover returns the cover url to the "first" edition. It takes size as an argument; it can be (S, M, or L)

func (*Work) Desc

func (w *Work) Desc() (string, error)

func (*Work) Editions

func (w *Work) Editions() ([]Book, error)

func (Work) FirstCoverKey

func (w Work) FirstCoverKey() string

FirstCoverKey return the first cover key (if it exists)

func (*Work) Key

func (w *Work) Key() (string, error)

func (*Work) KeyAuthors

func (w *Work) KeyAuthors() ([]string, error)

func (*Work) KeyCovers

func (w *Work) KeyCovers() ([]string, error)

func (*Work) Load

func (w *Work) Load()

Load parses the json container and fills all the fields

func (*Work) Subjects

func (w *Work) Subjects() ([]string, error)

func (*Work) Title

func (w *Work) Title() (string, error)

Jump to

Keyboard shortcuts

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