openbd

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2022 License: Apache-2.0 Imports: 12 Imported by: 1

README

openbd-api -- APIs for openBD by Golang

check vulns lint status GitHub license GitHub release

This package is required Go 1.16 or later.

Migrated repository to github.com/goark/openbd-api

Usage of package

Import Package
import "github.com/goark/openbd-api"
Lookup openBD Book Data
books, err := openbd.DefaultClient().LookupBook([]string{"9784797369915", "9784274069321"})

Entities for openBD

Book type
//Book is entity class of book info.
type Book struct {
    Onix    Onix    `json:"onix"`
    Hanmoto Hanmoto `json:"hanmoto"`
    Summary Summary `json:"summary"`
}

//Onix is entity class of JPRO-onix items
type Onix struct {
    RecordReference   string //ISBN code (key code)
    NotificationType  string
    ProductIdentifier struct {
        ProductIDType string
        IDValue       string //ISBN ?
    }
    DescriptiveDetail struct {
        ProductComposition string
        ProductForm        string
        Measure            []struct {
            MeasureType     string
            Measurement     string
            MeasureUnitCode string
        } `json:",omitempty"`
        Collection struct {
            CollectionType     string
            CollectionSequence *struct {
                CollectionSequenceType     string `json:",omitempty"`
                CollectionSequenceTypeName string `json:",omitempty"`
                CollectionSequenceNumber   string `json:",omitempty"`
            } `json:",omitempty"`
            TitleDetail *struct {
                TitleType    string `json:",omitempty"`
                TitleElement []struct {
                    TitleElementLevel string
                    TitleText         struct {
                        Content      string `json:"content"`
                        CollationKey string `json:"collationkey,omitempty"`
                    }
                } `json:",omitempty"`
            } `json:",omitempty"`
        }
        TitleDetail struct {
            TitleType    string
            TitleElement struct {
                TitleElementLevel string
                TitleText         struct {
                    Content      string `json:"content"`
                    Collationkey string `json:"collationkey,omitempty"`
                }
            }
        }
        Contributor []struct {
            SequenceNumber  string
            ContributorRole []string `json:",omitempty"`
            PersonName      struct {
                Content      string `json:"content"`
                Collationkey string `json:"collationkey,omitempty"`
            }
            BiographicalNote string `json:",omitempty"`
        } `json:",omitempty"`
        Language []struct {
            LanguageRole string
            LanguageCode string
            CountryCode  string
        } `json:",omitempty"`
        Extent []struct {
            ExtentType  string
            ExtentValue string
            ExtentUnit  string
        } `json:",omitempty"`
        Subject []struct {
            SubjectSchemeIdentifier string
            SubjectCode             string
            SubjectHeadingText      string `json:",omitempty"`
        } `json:",omitempty"`
        Audience []struct {
            AudienceCodeType  string
            AudienceCodeValue string
        } `json:",omitempty"`
    }
    CollateralDetail *struct {
        TextContent []struct {
            TextType        string
            ContentAudience string
            Text            string
        } `json:",omitempty"`
        SupportingResource []struct {
            ResourceContentType string
            ContentAudience     string
            ResourceMode        string
            ResourceVersion     []struct {
                ResourceForm           string
                ResourceVersionFeature []struct {
                    ResourceVersionFeatureType string
                    FeatureValue               string
                } `json:",omitempty"`
                ResourceLink string
            } `json:",omitempty"`
        } `json:",omitempty"`
    } `json:",omitempty"`
    PublishingDetail struct {
        Imprint struct {
            ImprintIdentifier []struct {
                ImprintIDType string
                IDValue       string
            } `json:",omitempty"`
            ImprintName string
        }
        Publisher struct {
            PublisherIdentifier []struct {
                PublisherIDType string
                IDValue         string
            } `json:",omitempty"`
            PublishingRole string
            PublisherName  string
        }
        PublishingDate []struct {
            Date               Date
            PublishingDateRole string
        } `json:",omitempty"`
    }
    ProductSupply struct {
        SupplyDetail struct {
            ReturnsConditions struct {
                ReturnsCodeType string
                ReturnsCode     string
            }
            ProductAvailability string
            Price               []struct {
                PriceType    string
                CurrencyCode string
                PriceAmount  string
            } `json:",omitempty"`
        }
    }
}

//Hanmoto is entity class of Hanmoto dot com items
type Hanmoto struct {
    DatePublished Date `json:"dateshuppan"`
    DateModified  Date `json:"datemodified"`
    DateCreated   Date `json:"datecreated"`
    DateReleased  Date `json:"datekoukai"`
    IsLightNovel  bool `json:"lanove,omitempty"`
    HasReview     bool `json:"hasshohyo,omitempty"`
    Reviews       []struct {
        Reviewer       string `json:"reviewer"`
        Link           string `json:"link"`
        DateAppearance Date   `json:"appearance"`
        SourceKindID   int    `json:"kubun_id"`
        SourceID       int    `json:"source_id"`
        Source         string `json:"source"`
        PaperType      string `json:"choyukan"`
        PostUser       string `json:"post_user"`
        Han            string `json:"han"`
        Gou            string `json:"gou"`
    } `json:"reviews,omitempty"`
    HasSample bool `json:"hastameshiyomi,omitempty"`
}

//Summary is entity class of summary data
type Summary struct {
    ISBN      string `json:"isbn"`
    Title     string `json:"title"`
    Volume    string `json:"volume"`
    Series    string `json:"series"`
    Publisher string `json:"publisher"`
    PubDate   Date   `json:"pubdate"`
    Author    string `json:"author"`
    Cover     string `json:"cover"`
}

Command Line Interface (Sample Code)

Download and Build
$ go get github.com/goark/openbd-api/cli/openbd
Lookup openBD Books Data
$ openbd lookup 9784797369915 9784274069321

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNullPointer = errors.New("Null reference instance")
	ErrHTTPStatus  = errors.New("Bad HTTP status")
	ErrNoData      = errors.New("No response data")
)

Functions

func EncodeBook

func EncodeBook(book *Book) ([]byte, error)

EncodeBook returns bytes encoded from Book instance

func EncodeBooks

func EncodeBooks(books []Book) ([]byte, error)

EncodeBooks returns bytes encoded from list of Book

Types

type Book

type Book struct {
	Onix    Onix    `json:"onix"`
	Hanmoto Hanmoto `json:"hanmoto"`
	Summary Summary `json:"summary"`
}

Book is entity class of book info.

func DecodeBook

func DecodeBook(b []byte) (*Book, error)

DecodeBook returns Book instance from byte buffer

func DecodeBooks

func DecodeBooks(b []byte) ([]Book, error)

DecodeBooks returns array of Book instance from byte buffer

func (*Book) Authors

func (book *Book) Authors() []string

Authors returns strings of Contributors

func (*Book) Description

func (book *Book) Description() string

Description returns strings of book description or table of content

func (*Book) ISBN

func (book *Book) ISBN() string

ISBN returns ISBN code

func (*Book) Id

func (book *Book) Id() string

Id returns id code (= Book.Onix.RecordReference)

func (*Book) ImageURL

func (book *Book) ImageURL() string

ImageURL returns string of book cover image URL

func (*Book) IsValid

func (book *Book) IsValid() bool

IsValid returns true if Book is valid data

func (*Book) Label

func (book *Book) Label() string

Label returns string of book label

func (*Book) PublicationDate

func (book *Book) PublicationDate() Date

PublicationDate returns Date of Publication

func (*Book) Publisher

func (book *Book) Publisher() string

Publisher returns strings of Publisher

func (*Book) SeriesTitle

func (book *Book) SeriesTitle() string

SeriesTitle returns string of series title

func (*Book) String

func (book *Book) String() string

func (*Book) SubTitle

func (book *Book) SubTitle() string

SubTitle returns string of sub-title

func (*Book) Title

func (book *Book) Title() string

Title returns string of Book Title

type Client

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

Client is http.Client for Aozora API Server

func DefaultClient

func DefaultClient() *Client

DefaultClient returns new Client instance with default setting

func (*Client) LookupBooks

func (c *Client) LookupBooks(ids []string) ([]Book, error)

LookupBooks gets books data (struct data)

func (*Client) LookupBooksContext

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

LookupBooksRawContext gets books data with context.Context. (struct data)

func (*Client) LookupBooksRaw

func (c *Client) LookupBooksRaw(ids []string) ([]byte, error)

LookupBooksRaw gets books data (raw data)

func (*Client) LookupBooksRawContext

func (c *Client) LookupBooksRawContext(ctx context.Context, ids []string) ([]byte, error)

LookupBooksRawContext gets books data with context.Context. (raw data)

type ClientOptFunc

type ClientOptFunc func(*Client)

ClientOptFunc is self-referential function for functional options pattern

func WithContext

func WithContext(ctx context.Context) ClientOptFunc

WithContext is dummy function. Because this function is deprecated.

func WithHttpClient

func WithHttpClient(client *http.Client) ClientOptFunc

WithHttpClient returns function for setting http.Client

type Date

type Date struct {
	time.Time
}

Time is wrapper class of time.Time

func NewDate

func NewDate(tm time.Time) Date

NewDate returns Time instance

func (*Date) MarshalJSON

func (t *Date) MarshalJSON() ([]byte, error)

MarshalJSON returns time string with RFC3339 format

func (Date) String

func (t Date) String() string

func (*Date) UnmarshalJSON

func (t *Date) UnmarshalJSON(b []byte) error

UnmarshalJSON returns result of Unmarshal for json.Unmarshal()

type Hanmoto

type Hanmoto struct {
	DatePublished Date `json:"dateshuppan"`
	DateModified  Date `json:"datemodified"`
	DateCreated   Date `json:"datecreated"`
	DateReleased  Date `json:"datekoukai"`
	IsLightNovel  bool `json:"lanove,omitempty"`
	HasReview     bool `json:"hasshohyo,omitempty"`
	Reviews       []struct {
		Reviewer       string `json:"reviewer"`
		Link           string `json:"link"`
		DateAppearance Date   `json:"appearance"`
		SourceKindID   int    `json:"kubun_id"`
		SourceID       int    `json:"source_id"`
		Source         string `json:"source"`
		PaperType      string `json:"choyukan"`
		PostUser       string `json:"post_user"`
		Han            string `json:"han"`
		Gou            string `json:"gou"`
	} `json:"reviews,omitempty"`
	HasSample bool `json:"hastameshiyomi,omitempty"`
}

Hanmoto is entity class of Hanmoto dot com items

type Onix

type Onix struct {
	RecordReference   string //ISBN code (key code)
	NotificationType  string
	ProductIdentifier struct {
		ProductIDType string
		IDValue       string //ISBN ?
	}
	DescriptiveDetail struct {
		ProductComposition string
		ProductForm        string
		Measure            []struct {
			MeasureType     string
			Measurement     string
			MeasureUnitCode string
		} `json:",omitempty"`
		Collection struct {
			CollectionType     string
			CollectionSequence *struct {
				CollectionSequenceType     string `json:",omitempty"`
				CollectionSequenceTypeName string `json:",omitempty"`
				CollectionSequenceNumber   string `json:",omitempty"`
			} `json:",omitempty"`
			TitleDetail *struct {
				TitleType    string `json:",omitempty"`
				TitleElement []struct {
					TitleElementLevel string
					TitleText         struct {
						Content      string `json:"content"`
						CollationKey string `json:"collationkey,omitempty"`
					}
				} `json:",omitempty"`
			} `json:",omitempty"`
		}
		TitleDetail struct {
			TitleType    string
			TitleElement struct {
				TitleElementLevel string
				TitleText         struct {
					Content      string `json:"content"`
					Collationkey string `json:"collationkey,omitempty"`
				}
			}
		}
		Contributor []struct {
			SequenceNumber  string
			ContributorRole []string `json:",omitempty"`
			PersonName      struct {
				Content      string `json:"content"`
				Collationkey string `json:"collationkey,omitempty"`
			}
			BiographicalNote string `json:",omitempty"`
		} `json:",omitempty"`
		Language []struct {
			LanguageRole string
			LanguageCode string
			CountryCode  string
		} `json:",omitempty"`
		Extent []struct {
			ExtentType  string
			ExtentValue string
			ExtentUnit  string
		} `json:",omitempty"`
		Subject []struct {
			SubjectSchemeIdentifier string
			SubjectCode             string
			SubjectHeadingText      string `json:",omitempty"`
		} `json:",omitempty"`
		Audience []struct {
			AudienceCodeType  string
			AudienceCodeValue string
		} `json:",omitempty"`
	}
	CollateralDetail *struct {
		TextContent []struct {
			TextType        string
			ContentAudience string
			Text            string
		} `json:",omitempty"`
		SupportingResource []struct {
			ResourceContentType string
			ContentAudience     string
			ResourceMode        string
			ResourceVersion     []struct {
				ResourceForm           string
				ResourceVersionFeature []struct {
					ResourceVersionFeatureType string
					FeatureValue               string
				} `json:",omitempty"`
				ResourceLink string
			} `json:",omitempty"`
		} `json:",omitempty"`
	} `json:",omitempty"`
	PublishingDetail struct {
		Imprint struct {
			ImprintIdentifier []struct {
				ImprintIDType string
				IDValue       string
			} `json:",omitempty"`
			ImprintName string
		}
		Publisher struct {
			PublisherIdentifier []struct {
				PublisherIDType string
				IDValue         string
			} `json:",omitempty"`
			PublishingRole string
			PublisherName  string
		}
		PublishingDate []struct {
			Date               Date
			PublishingDateRole string
		} `json:",omitempty"`
	}
	ProductSupply struct {
		SupplyDetail struct {
			ReturnsConditions struct {
				ReturnsCodeType string
				ReturnsCode     string
			}
			ProductAvailability string
			Price               []struct {
				PriceType    string
				CurrencyCode string
				PriceAmount  string
			} `json:",omitempty"`
		}
	}
}

Onix is entity class of JPRO-onix items

type Server

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

Server is informations of openBD

func New

func New(opts ...ServerOptFunc) *Server

New returns new Server instance

func (*Server) CreateClient

func (s *Server) CreateClient(opts ...ClientOptFunc) *Client

CreateClient returns new Client instance

func (*Server) URL

func (s *Server) URL() *url.URL

URL returns url.URL instance

type ServerOptFunc

type ServerOptFunc func(*Server)

ServerOptFunc is self-referential function for functional options pattern

func WithScheme

func WithScheme(scheme string) ServerOptFunc

WithScheme returns function for setting scheme

func WithServerName

func WithServerName(host string) ServerOptFunc

WithServerName returns function for setting hostname

type Summary

type Summary struct {
	ISBN      string `json:"isbn"`
	Title     string `json:"title"`
	Volume    string `json:"volume"`
	Series    string `json:"series"`
	Publisher string `json:"publisher"`
	PubDate   Date   `json:"pubdate"`
	Author    string `json:"author"`
	Cover     string `json:"cover"`
}

Summary is entity class of summary data

Directories

Path Synopsis
cli

Jump to

Keyboard shortcuts

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