Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
dynamic-websites/exercises/12_spa/books/modules/books.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
54 lines (45 sloc)
1.3 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
/* eslint-disable no-magic-numbers */ | |
const rest = require('rest') | |
const google = require('./google') | |
const minQueryLen = 3 | |
// module.exports.search = request => new Promise( async resolve => { | |
// console.log(request.query) | |
// if(!request.query.q || request.query.q.length <= minQueryLen) { | |
// console.log('no querystring') | |
// return resolve({status: 200, data: []}) | |
// } | |
// const url = this.buildString('java', 2) | |
// const data = await rest(url) | |
// //console.log(data) | |
// }) | |
/* -------------------------------------------------------------------------- */ | |
/** Makes a Google Books API query | |
* | |
* @param {String} searchString the URL to use for the query | |
*/ | |
module.exports.searchGoogle = async searchString => { | |
//console.log('calling function searchGoogle') | |
//console.log(searchString) | |
const data = await google.search(searchString) | |
//console.log(data) | |
return data | |
} | |
module.exports.extractFields = jsonStr => { | |
const bookArray = [] | |
const json = JSON.parse(jsonStr) | |
if(!Array.isArray(json.items)) throw new Error('no book data found') | |
for(const n of json.items) { | |
let item = {} | |
console.log(n) | |
item.title = n.volumeInfo.title | |
for(const m in n.industryIdentifiers) { | |
//console.log(m) | |
if(m.type === 'ISBN_13') { | |
// xxx | |
} | |
} | |
bookArray.push(item) | |
} | |
return bookArray | |
} |