UNPKG

gatsby-source-nytimes-books-api

Version:

This [GatsyJS](https://gatsbyjs.org) source plugin fetches data from the [NYTimes Books API](https://developer.nytimes.com/docs/books-product/1/overview)

31 lines (26 loc) 825 B
const axios = require("axios") const getResults = require("./getResults") const getQueryString = require("./getQueryString") const { NYTIMES_API, BEST_SELLERS_ENDPT } = require("../constants") function getBestSellersHistory(options, reporter) { const { token, ...params } = options const queryObj = { "api-key": token } let apiUrl = `${NYTIMES_API}${BEST_SELLERS_ENDPT}` const acceptedParams = [ "age-group", "author", "contributor", "isbn", "offset", "price", "publisher", "title", ] const queryString = getQueryString(params, acceptedParams, queryObj) apiUrl = `${apiUrl}?${queryString}` return axios(apiUrl) .then(data => getResults(data)) .catch(err => reporter.error(`Could not get book reviews: ${err}`)) } module.exports = getBestSellersHistory // a changes