Skip to content
Permalink
c9088412c4
Switch branches/tags

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?
Go to file
 
 
Cannot retrieve contributors at this time
46 lines (37 sloc) 1.17 KB
'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) {
console.log(n)
bookArray.push({title: n.volumeInfo.title})
}
return bookArray
}