goisbn

package module
v0.0.0-...-059f94f Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2021 License: MIT Imports: 11 Imported by: 2

README

go-isbn

GoDoc Go Report Card codecov License

Feature Overview

  • Retrieves book details using ISBN10 / ISBN13 from 4 providers:
    • Google Books
    • Open Library
    • Goodreads (requires env var GOODREAD_APIKEY to be set) free
    • ISBNDB (requires env var ISBNDB_APIKEY to be set) 7-day trial
  • Validates if a string is in valid ISBN10 / ISBN13 format

go-isbn will spawn equal number of go routines each querying a single provider with a max timeout of 3 seconds. First valid result will then be returned. Will return book not found only if all providers fail. Will default to all available providers if none is specified

Guide

Installation
go get github.com/abx123/go-isbn
Example

Querying on all 4 providers:

package main

import (
  "fmt"
  "log"

  goisbn "github.com/abx123/go-isbn"
)

func main() {
  // go-isbn instance
  gi := goisbn.NewGoISBN(goisbn.DEFAULT_PROVIDERS)

  // Get book details
  book, err := gi.Get("9780099588986")
  if err != nil{
    log.Fatalln(err)
  }
  fmt.Println(book)

Querying on selected providers:

package main

import (
  "fmt"
  "log"

  goisbn "github.com/abx123/go-isbn"
)

func main() {
  // go-isbn instance
  gi := goisbn.NewGoISBN([]string{
    goisbn.ProviderGoogle,
    goisbn.ProviderGoodreads,
  })

  // Get book details
  book, err := gi.Get("9780099588986")
  if err != nil{
    log.Fatalln(err)
  }
  fmt.Println(book)

Documentation

Index

Constants

View Source
const (

	// ProviderGoogle is the constant representation for Google Books
	ProviderGoogle = "google"
	// ProviderOpenLibrary is the constant representation for Open Library
	ProviderOpenLibrary = "openlibrary"
	// ProviderGoodreads is the constant representation for Goodreads
	ProviderGoodreads = "goodreads"
	// ProviderIsbndb is the constant representation for ISBNDB
	ProviderIsbndb = "isbndb"
)

Variables

DEFAULT_PROVIDERS contains all available providers, ie: Google Books, Open Library, Goodreads, & ISBNDB

Functions

This section is empty.

Types

type Book

type Book struct {
	Title               string      `json:"title"`
	PublishedYear       string      `json:"published_year"`
	Authors             []string    `json:"authors"`
	Description         string      `json:"description"`
	IndustryIdentifiers *Identifier `json:"industry_identifiers"`
	PageCount           int64       `json:"page_count"`
	Categories          []string    `json:"categories"`
	ImageLinks          *ImageLinks `json:"image_links"`
	Publisher           string      `json:"publisher"`
	Language            string      `json:"language"`
	Source              string      `json:"source"`
}

Book contains all the data retreived from providers

type GoISBN

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

GoISBN contains the providers and their respective resolver function with API Key for Goodreads and ISBNDB provider

func NewGoISBN

func NewGoISBN(providers []string) *GoISBN

NewGoISBN generates a new instance of GoISBN

func (*GoISBN) Get

func (gi *GoISBN) Get(isbn string) (*Book, error)

Get retreives the details of a book with the ISBN provided from previously initialized providers

func (*GoISBN) ValidateISBN

func (gi *GoISBN) ValidateISBN(isbn string) bool

ValidateISBN checks if the input isbn is in a valid ISBN 10 or ISBN 13 format

type Identifier

type Identifier struct {
	ISBN   string `json:"isbn"`
	ISBN13 string `json:"isbn_13"`
}

Identifier contains the ISBN 10 and ISBN 13 data

type ImageLinks struct {
	SmallImageURL string `json:"small_image_url"`
	ImageURL      string `json:"image_url"`
	LargeImageURL string `json:"large_image_url"`
}

ImageLinks contains all the image links related to the book

type Queryer

type Queryer interface {
	Get(string) (*Book, error)
	ValidateISBN(string) bool
}

Queryer is the main interface for GoISBN

Jump to

Keyboard shortcuts

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