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

npr-api

v2.0.1

Published

Node.js NPR API client

Downloads

14

Readme

Node.js NPR API Build Status

A Node.js package for accessing NPR APIs.

Requirements

This module is a npm package, and requires the latest stable version of node.js.

$ node -v
v6.2.0

Installation

$ mkdir npr_test && cd npr_test
$ npm install npr-api

Usage

As of right now, the full NPR One API is available in this package. It is also set up in a way where it will support the future addition of other NPR 'Open APIs' by adding additional API modules to the lib/ folder.

Example

First, you will need to create a new file called get_token.js in your favorite text editor.

$ vim get_token.js

Then, paste the example below into the file and update the creditials to match your NPR Developer account info.

const NPR = require('npr-api'),
      npr = new NPR();

const client_id = 'your_oauth_client_id',
      client_secret = 'your_oauth_client_secret';

npr.one.init()
   .then(function() {

     return npr.one.authorization
      .generateDeviceCode({
         client_id: client_id,
         client_secret: client_secret,
         scope: 'listening.write identity.readonly'
       });

   })
  .then(function(res) {

    return new Promise(function(resolve, reject) {

      console.log('Please visit the following URL:');
      console.log(`${res.verification_uri}\n`);
      console.log(`Enter code: ${res.user_code}\n`);
      console.log('Press the Spacebar when complete.');

      process.stdin.setRawMode(true);
      process.stdin.resume();

      process.stdin.on('data', function() {
        resolve(res.device_code);
      });

    });

  })
  .then(function(code) {
    return npr.one.authorization
      .createToken({
         grant_type: 'device_code',
         client_id: client_id,
         client_secret: client_secret,
         code: code
       });
  })
  .then(function(res) {
    console.log(`ACCESS TOKEN: ${res.access_token}`);
    process.exit();
  })
  .catch(function(err) {
    console.log(err.statusText);
    process.exit(1);
  });

Then, run the example using node.

$ node get_token.js

You will only need this once to get an access token to use from now on. Next, you will need to create a new file called get_recommendations.js in your favorite text editor.

$ vim get_recommendations.js

Then, paste the example below into the file and update the creditials to match your NPR Developer account info.

const NPR = require('npr-api'),
      npr = new NPR();

// paste in your token here
const token = 'access_token_from_step_1';

npr.one.init(token)
  .then(function() {
    return npr.one.listening.getRecommendations({ channel: 'npr' });
  })
  .then(function(recommendations) {
    // print out the first two recommendations to the console
    console.log(recommendations.items.slice(0,2));
  }).catch(console.err);

Then, run the example using node.

$ node get_recommendations.js

You should then see a couple of the listening recommendations for your NPR account dumped to your terminal's stdout.

NPR ONE APIs

More information about the NPR One API can be found at the NPR One Developer Center.

  • Authorization
    • npr.one.authorization.createToken()
    • npr.one.authorization.generateDeviceCode()
    • npr.one.authorization.getAuthorizationPage()
  • Identity
    • npr.one.identity.getUser()
    • npr.one.identity.postFollowing()
    • npr.one.identity.updateFollowingStatus()
    • npr.one.identity.updateStations()
  • Listening
    • npr.one.listening.getAggRecommendations()
    • npr.one.listening.getChannels()
    • npr.one.listening.getHistory()
    • npr.one.listening.getRecommendations()
    • npr.one.listening.getSearchRecommendations()
    • npr.one.listening.postRating()
  • Local Activation
    • npr.one.localactivation.sendDonationEmail()
  • Sponsorship
    • npr.one.sponsorship.getAds()
    • npr.one.sponsorship.receiveAdTracking()

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Gulp.

License

Copyright (c) 2015 Adafruit Industries. Licensed under the MIT license.