npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gatsby-source-nytimes-books-api

v1.0.1

Published

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

Downloads

8

Readme

Gatsby Source NYTimes Books API Plugin

This GatsyJS source plugin fetches data from the NYTimes Books API

How to install

npm i gatsby-source-nytimes-books-api

How to use

Add a config object to your Gatsby config.js file. You must include an api key obtained from the NYTimes Developer Network

// config.js
{
  resolve: "gatsby-source-nytimes-books-api",
  options: {
    token: 'YOUR_API_KEY', // aqcuire from the NYTimes api site
    type: 'history' // the books data you want access to
    // additional properties for query parameters
  }
}

Available Types

There are six different endpoints available from the NYTimes Books API. Each endpoint has a corresponding type that can be set to pull data from. Below are the available types and the endpoints they correspond to. Check out the NYTimes Books API documentation to learn more about what parameters are available and required to successfully create a query.

lists

Get Best Sellers list. If no date is provided returns the latest list.

date-list

Get Best Sellers list by date.

names-list

Get Best Sellers list names.

overview

Get top 5 books for all the Best Sellers lists for specified date.

reviews

Get book reviews.

history

Get Best Sellers list history.

Passing Query Parameter Values

The books API allows you to query best sellers lists, reviews and books by passing any number of different parameter values. To pass in parameter values to the source plugin, include the parameter name and value as a property of the options object in your config.js file. For example, to use the overview type you can set a publish_date property:

// config.js
{
  resolve: "gatsby-source-nytimes-books-api",
  options: {
    token: 'YOUR_API_KEY',
    type: 'overview'
    published_date: "2018-10-10" // available query param value specified in the NYTimes docs
  }
}

The additional properties in the options object will be used to construct the URL for the API call:

https://api.nytimes.com/svc/books/v3/lists/overview.json?published_date=2018-10-10&api-key=[YOUR_API_KEY]

Use the NYTimes Books API documentation to determine which parameters can be passed.

How to query for data

lists

query {
  allTimesBooksList {
    nodes {
      amazon_product_url
      asterisk
      bestsellers_date
      book_details {
        age_group
        author
        contributor
        contributor_note
        description
        price
        primary_isbn10
        primary_isbn13
        publisher
        title
      }
      dagger
      display_name
      id
      isbns {
        isbn10
        isbn13
      }
      list_name
      published_date
      rank
      rank_last_week
      weeks_on_list
      reviews {
        article_chapter_link
        book_review_link
        first_chapter_link
        sunday_review_link
      }
    }
  }
}

names-list

query {
  allTimesBooksListName {
    nodes {
      display_name
      list_name
      list_name_encoded
      newest_published_date
      oldest_published_date
      updated
      id
    }
  }
}

date-list

Explorer
query 
MyQuery
Docs
query {
  allTimesBooksDateList {
    nodes {
      bestsellers_date
      books {
        age_group
        amazon_product_url
        article_chapter_link
        asterisk
        author
        book_image
        book_image_height
        book_image_width
        book_review_link
        book_uri
        buy_links {
          name
          url
        }
        contributor
        contributor_note
        dagger
        description
        first_chapter_link
        isbns {
          isbn10
          isbn13
        }
        price
        primary_isbn10
        primary_isbn13
        publisher
        rank
        rank_last_week
        sunday_review_link
        title
        weeks_on_list
      }
      display_name
      id
      internal {
        content
        contentDigest
        description
        fieldOwners
        ignoreType
        mediaType
        owner
        type
      }
      list_name
      list_name_encoded
      next_published_date
      normal_list_ends_at
      previous_published_date
      published_date
      published_date_description
    }
    totalCount
  }
}

history


query {
  allTimesBooksBestSellerHistory {
    nodes {
      age_group
      author
      contributor
      contributor_note
      description
      id
      internal {
        content
        contentDigest
        description
        fieldOwners
        ignoreType
        mediaType
        owner
        type
      }
      isbns {
        isbn10
        isbn13
      }
      price
      publisher
      ranks_history {
        asterisk
        bestsellers_date
        dagger
        display_name
        list_name
        primary_isbn10
        primary_isbn13
        published_date
        rank
        weeks_on_list
      }
      reviews {
        article_chapter_link
        book_review_link
        first_chapter_link
        sunday_review_link
      }
      title
    }
  }
}

overview

query {
  allTimesBooksListOverview {
    nodes {
      bestsellers_date
      id
      internal {
        content
        contentDigest
        description
        fieldOwners
        ignoreType
        mediaType
        owner
        type
      }
      lists {
        display_name
        list_id
        list_image
        list_image_height
        list_image_width
        list_name
        list_name_encoded
        updated
      }
      next_published_date
      previous_published_date
      published_date
      published_date_description
    }
  }
}

reviews

query MyQuery {
  allTimesBooksReview {
    nodes {
      book_author
      book_title
      byline
      id
      internal {
        content
        contentDigest
        description
        fieldOwners
        ignoreType
        mediaType
        owner
        type
      }
      isbn13
      publication_dt
      summary
      url
      uri
      uuid
    }
  }
}

How to run tests

npm test

How to develop locally

To work on this plugin locally take a look at Gatsby's documentation on creating a local plugin. Essentially, you will need to include this plugin in a plugins directory of another project to test changes.

How to contribute

Check out the CONTRIBUTING guide to find out how you can get involved!