Skip to content
/ gotendex Public

Wrapper for JSON web API for Project Gutenberg ebook metadata

Notifications You must be signed in to change notification settings

pab-h/gotendex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gotendex

Wrapper for JSON web API for Project Gutenberg ebook metadata, see here

How install

go get https://github.com/pab-h/gotendex

Books

The gutendex.com/books endpoint is binded by the method

func (api Api) Books() *src.Response

The book struct is

type Book struct {
	Id            int               `json:"id"`
	Title         string            `json:"title"`
	Subjects      []string          `json:"subjects"`
	Authors       []Person          `json:"authors"`
	Translators   []Person          `json:"translators"`
	Bookshelves   []string          `json:"bookshelves"`
	Languages     []string          `json:"languages"`
	Copyright     bool              `json:"copyright"`
	MediaType     string            `json:"media_type"`
	Formats       map[string]string `json:"formats"`
	DownloadCount int               `json:"download_count"`
}

Query Books

You can make a query using the method

func (api Api) QueryBooks(query *Query) *src.Response

The Query struct is

type Query struct {
	AuthorYearStart int
	AuthorYearEnd   int
	Copyright       bool
	Ids             []int
	Languages       []string
	MimeType        string
	Search          string
	Sort            []string
	Topic           string
}

Pagination

You can navigate the pagination using the following methods:

func (api Api) Next(response *src.Response) (*src.Response, bool)
func (api Api) Previous(response *src.Response) (*src.Response, bool)

The return bool indicates whether you were able to continue

Example

package main

import (
	"fmt"

	"github.com/pab-h/gotendex"
)

func main() {
	api := gotendex.NewApi()

	responseBooks := api.Books()

	fmt.Println("cout:", responseBooks.Count)

	for _, book := range responseBooks.Results {
		fmt.Println("Id:", book.Id)
		fmt.Println("Title:", book.Title)
	}

}

Example with query

package main

import (
	"fmt"

	"github.com/pab-h/gotendex"
)

func main() {
	api := gotendex.NewApi()

	query := gotendex.Query{
		Languages: []string{"fr", "fi"},
	}

	responseBooks := api.QueryBooks(&query)

	fmt.Println("cout:", responseBooks.Count)

	for _, book := range responseBooks.Results {
		fmt.Println("Id:", book.Id)
		fmt.Println("Title:", book.Title)
	}

}

Example with pagination

package main

import (
	"fmt"

	"github.com/pab-h/gotendex"
)

func main() {
	api := gotendex.NewApi()

	query := gotendex.Query{
		Languages: []string{"fr", "fi"},
	}

	responseBooks := api.QueryBooks(&query)
	responseBooks, canGo := api.Next(responseBooks)

	if canGo {
		fmt.Println(" You can not go")
	}

	fmt.Println("cout:", responseBooks.Count)

	for _, book := range responseBooks.Results {
		fmt.Println("Id:", book.Id)
		fmt.Println("Title:", book.Title)
	}

}

About

Wrapper for JSON web API for Project Gutenberg ebook metadata

Topics

Resources

Stars

Watchers

Forks

Languages