Skip to content

Commit

Permalink
Update document
Browse files Browse the repository at this point in the history
  • Loading branch information
spiegel-im-spiegel committed Jul 27, 2019
1 parent 4bd39d0 commit ae2207a
Show file tree
Hide file tree
Showing 7 changed files with 224 additions and 16 deletions.
213 changes: 210 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,220 @@
# [books-data] -- Search for Books Data

[![Build Status](https://travis-ci.org/spiegel-im-spiegel/books-data.svg?branch=master)](https://travis-ci.org/spiegel-im-spiegel/books-data)
[![GitHub license](https://img.shields.io/badge/license-Apache%202-blue.svg)](https://raw.githubusercontent.com/spiegel-im-spiegel/books-data/master/LICENSE)
[![GitHub release](http://img.shields.io/github/release/spiegel-im-spiegel/books-data.svg)](https://github.com/spiegel-im-spiegel/books-data/releases/latest)

## Download and Build

```
$ go get github.com/spiegel-im-spiegel/books-data@latest
```

### Binaries

See [latest release](https://github.com/spiegel-im-spiegel/books-data/releases/latest).

## Usage

```
$ books-data -h
Search for books data
Usage:
books-data [flags]
books-data [command]
Available Commands:
help Help about any command
openbd Search for books data by openBD
paapi Search for books data by PA-API
version Print the version number
Flags:
--debug for debug
-h, --help help for books-data
--pipe Import description from Stdin
--raw Output raw data from openBD
Use "books-data [command] --help" for more information about a command.
```

### Search for books data from [openBD]

```
$ books-data openbd -h
Search for books data by openBD
Usage:
books-data openbd [flags] [description]
Flags:
-h, --help help for openbd
-i, --isbn string ISBN code
-r, --rating int Rating of product
--review-date string Date of review
-t, --template string Template file
Global Flags:
--debug for debug
--pipe Import description from Stdin
--raw Output raw data from openBD
$ books-data openbd -i 427406932X -r 5 "This book is Interesting." | jq .
{
"Book": {
"ID": "9784274069321",
"Title": "リーン開発の現場 : カンバンによる大規模プロジェクトの運営",
"Image": {
"URL": "https://cover.openbd.jp/9784274069321.jpg",
"Height": 0,
"Width": 0
},
"ProductType": "Book",
"Authors": [
"Kniberg,Henrik/著 オーム社/著 オーム社開発局/著 市谷聡啓/翻訳 ほか"
],
"Publisher": "オーム社",
"Codes": [
{
"Name": "ISBN",
"Value": "9784274069321"
}
],
"PublicationDate": "2013-10-01",
"LastRelease": "0001-01-01",
"Service": {
"Name": "openBD",
"URL": "https://openbd.jp/"
}
},
"Date": "2019-07-27",
"Rating": 5,
"Star": [
true,
true,
true,
true,
true
],
"Description": "This book is Interesting."
}
$ books-data openbd -i 427406932X -r 5 "This book is Interesting." -t template/template.bib.txt
@BOOK{Book:9784274069321,
TITLE = "リーン開発の現場 : カンバンによる大規模プロジェクトの運営",
AUTHOR = "Kniberg,Henrik/著 オーム社/著 オーム社開発局/著 市谷聡啓/翻訳 ほか",
PUBLISHER = {オーム社},
YEAR = 2013
}
```

### Search for books data by [PA-API]

```
$ cat ~/.paapi.yaml
marketplace: webservices.amazon.co.jp
associate-tag: mytag-20
access-key: AKIAIOSFODNN7EXAMPLE
secret-key: 1234567890
$ books-data paapi -h
Search for books data by PA-API
Usage:
books-data paapi [flags] [description]
Flags:
--access-key string PA-API: Access Key ID
-a, --asin string Amazon ASIN code
--associate-tag string PA-API: Associate Tag
--config string config file (default $HOME/.paapi.yaml)
-h, --help help for paapi
--marketplace string PA-API: Marketplace (default "webservices.amazon.co.jp")
-r, --rating int Rating of product
--review-date string Date of review
--secret-key string PA-API: Secret Access Key
-t, --template string Template file
Global Flags:
--debug for debug
--pipe Import description from Stdin
--raw Output raw data from openBD
$ books-data paapi -a 427406932X -r 5 "This book is Interesting." | jq .
{
"Book": {
"ID": "427406932X",
"Title": "リーン開発の現場 カンバンによる大規模プロジェクトの運営",
"URL": "https://www.amazon.co.jp/exec/obidos/ASIN/427406932X/mytag-20",
"Image": {
"URL": "https://images-fe.ssl-images-amazon.com/images/I/51llL1uygcL._SL160_.jpg",
"Height": 160,
"Width": 116
},
"ProductType": "単行本(ソフトカバー)",
"Authors": [
"Henrik Kniberg"
],
"Creators": [
{
"Name": "角谷 信太郎",
"Role": "翻訳"
},
{
"Name": "市谷 聡啓",
"Role": "翻訳"
},
{
"Name": "藤原 大",
"Role": "翻訳"
}
],
"Publisher": "オーム社",
"Codes": [
{
"Name": "ASIN",
"Value": "427406932X"
},
{
"Name": "EAN",
"Value": "9784274069321"
}
],
"PublicationDate": "2013-10-26",
"LastRelease": "0001-01-01",
"Service": {
"Name": "PA-API",
"URL": "https://affiliate.amazon.co.jp/assoc_credentials/home"
}
},
"Date": "2019-07-27",
"Rating": 5,
"Star": [
true,
true,
true,
true,
true
],
"Description": "This book is Interesting."
}
$ books-data paapi -a 427406932X -r 5 "This book is Interesting." -t template/template.bib.txt
@BOOK{Book:427406932X,
TITLE = "リーン開発の現場 カンバンによる大規模プロジェクトの運営",
AUTHOR = "Henrik Kniberg and 角谷 信太郎 (翻訳) and 市谷 聡啓 (翻訳) and 藤原 大 (翻訳)",
PUBLISHER = {オーム社},
YEAR = 2013
}
```

## Reference

- [DDRBoxman/go-amazon-product-api: Wrapper for the Amazon Product Advertising API](https://github.com/DDRBoxman/go-amazon-product-api)
- seihmd/openbd: openBD API written by Go](https://github.com/seihmd/openbd)
- [seihmd/openbd: openBD API written by Go](https://github.com/seihmd/openbd)
- [openBDのAPIライブラリをGoでつくりました - Qiita](https://qiita.com/seihmd/items/d1f8b3b54cbc93346d78)
- [しょうがないので Amazon アフィリエイト・リンク作成ツールを作ったですよ — リリース情報 | text.Baldanders.info](https://text.baldanders.info/release/2019/01/amazon-product-advertising-api/)
- [Amazon アイテム検索・情報取得ツール v0.2.1 をリリースした — リリース情報 | text.Baldanders.info](https://text.baldanders.info/release/2019/01/amazon-item-v0_2_1-is-released/)

[books-data]: https://github.com/spiegel-im-spiegel/books-data "spiegel-im-spiegel/books-data: Search for Books Data"
[openBD]: https://openbd.jp/
[PA-API]: https://affiliate.amazon.co.jp/assoc_credentials/home
1 change: 1 addition & 0 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/spiegel-im-spiegel/books-data/entity"
)

//API is interface class for searching book API
type API interface {
LookupBook(id string) (*entity.Book, error) //Lookup book data by API
LookupRawData(id string) (io.Reader, error) //Lookup raw data by API
Expand Down
18 changes: 9 additions & 9 deletions entity/book.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (c Code) String() string {
//Creator is entity class of creator info.
type Creator struct {
Name string
Role string `json:"Role,omitempty"`
Role string `json:",omitempty"`
}

func (c Creator) String() string {
Expand All @@ -37,21 +37,21 @@ func (c Creator) String() string {
type Book struct {
ID string
Title string
SubTitle string `json:"SubTitle,omitempty"`
SeriesTitle string `json:"SeriesTitle,omitempty"`
URL string `json:"URL,omitempty"`
SubTitle string `json:",omitempty"`
SeriesTitle string `json:",omitempty"`
URL string `json:",omitempty"`
Image struct {
URL string
Height uint16
Width uint16
} `json:"Image,omitempty"`
ProductType string
}
ProductType string `json:",omitempty"`
Authors []string
Creators []Creator `json:"Creators,omitempty"`
Creators []Creator `json:",omitempty"`
Publisher string
Codes []Code
PublicationDate values.Date `json:"PublicationDate,omitempty"`
LastRelease values.Date `json:"LastRelease,omitempty"`
PublicationDate values.Date
LastRelease values.Date
Service struct {
Name string
URL string
Expand Down
2 changes: 1 addition & 1 deletion facade/openbd.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
//newpaapiCmd returns cobra.Command instance for show sub-command
func newOpenBDCmd(ui *rwi.RWI) *cobra.Command {
openBDCmd := &cobra.Command{
Use: "openbd",
Use: "openbd [flags] [description]",
Short: "Search for books data by openBD",
Long: "Search for books data by openBD",
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down
2 changes: 1 addition & 1 deletion facade/paapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var (
//newpaapiCmd returns cobra.Command instance for show sub-command
func newPaApiCmd(ui *rwi.RWI) *cobra.Command {
paapiCmd := &cobra.Command{
Use: "paapi",
Use: "paapi [flags] [description]",
Short: "Search for books data by PA-API",
Long: "Search for books data by PA-API",
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down
2 changes: 1 addition & 1 deletion review/review.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type Review struct {
Date values.Date
Rating int
Star [MAX_STAR]bool
Description string
Description string `json:",omitempty"`
}

//LookupOptFunc is self-referential function for functional options pattern
Expand Down
2 changes: 1 addition & 1 deletion template/template.bib.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@BOOK{Book:{{ .Book.ID }},
TITLE = "{{ .Book.Title }}"{{ if .Book.Authors }},
AUTHOR = "{{ range $i, $v := .Book.Authors }}{{ if ne $i 0 }} and {{ end }}{{ $v }}{{ end }}"{{ end }}{{ if .Book.Publisher }},
AUTHOR = "{{ range $i, $v := .Book.Authors }}{{ if ne $i 0 }} and {{ end }}{{ $v }}{{ end }}{{ if .Book.Creators }}{{ range .Book.Creators }} and {{ . }}{{ end }}{{ end }}"{{ end }}{{ if .Book.Publisher }},
PUBLISHER = {{ "{" }}{{ .Book.Publisher }}{{ "}" }}{{ end }}{{ if gt .Book.PublicationDate.Year 1 }},
YEAR = {{ .Book.PublicationDate.Year }}{{ end }}
}

0 comments on commit ae2207a

Please sign in to comment.