Skip to content

Instantly share code, notes, and snippets.

@deguchi
Created May 28, 2021 02:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deguchi/1a64d4ecbba5a0fa57269d632a3716e2 to your computer and use it in GitHub Desktop.
Save deguchi/1a64d4ecbba5a0fa57269d632a3716e2 to your computer and use it in GitHub Desktop.
async getOpenBDInfo(item): Promise<any> {
const books = await fetch('https://api.openbd.jp/v1/get?isbn='+item.isbn).then(r => r.json()).catch(error => console.log(error))
if (books.length>0) {
const book = books[0]
console.log(book)
// 紹介・目次
let description = null
let descriptionLong = null
let tableOfContents = null
const CollateralDetails = book.onix.CollateralDetail.TextContent
if (CollateralDetails) {
for (const CollateralDetail of CollateralDetails) {
const TextType = CollateralDetail.TextType
if (TextType === '02') description = CollateralDetail.Text
if (TextType === '03') descriptionLong = CollateralDetail.Text
if (TextType === '04') tableOfContents = CollateralDetail.Text
}
}
const maegakinado = typeof book.hanmoto.maegakinado!=='undefined' ? book.hanmoto.maegakinado : null
const hastameshiyomi = typeof book.hanmoto.hastameshiyomi!=='undefined' ? book.hanmoto.hastameshiyomi : null
return {
'description': description,
'descriptionLong': descriptionLong,
'tableOfContents': tableOfContents,
'maegakinado': maegakinado,
'hastameshiyomi': hastameshiyomi,
}
}
return null
}
const openBDInfo = await this.getOpenBDInfo(viewItem)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment