No description
Find a file
Todd Treece f97b43b1e1 0.2.4
2015-08-02 10:36:58 -04:00
lib adds more usage details to the README 2015-08-02 10:11:19 -04:00
test small test tweaks so done() isn't called multiple times 2015-08-01 23:48:25 -04:00
.gitignore adds gitignore & npm package.json 2015-07-31 15:52:47 -04:00
.travis.yml adds travis 2015-08-01 20:04:08 -04:00
gulpfile.js adds travis 2015-08-01 20:04:08 -04:00
index.js adds main npr module 2015-08-01 20:06:15 -04:00
LICENSE adds license 2015-08-01 23:38:26 -04:00
package.json 0.2.4 2015-08-02 10:36:58 -04:00
README.md drops dotenv and chalk dependencies 2015-08-02 10:20:35 -04:00

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
v0.12.7

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.

Note: The only known limitation is that NPR One API module included in this package currently expects to use the grant_type of password to get new OAuth access tokens. The other authentication methods will be supported soon.

Example

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

$ vim index.js

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

var NPR = require('npr-api');

// edit the credentials to match your account info.
var npr = NPR({
  client_id: 'your_client_id',
  client_secret: 'your_client_secret',
  username: 'npr_username',
  password: 'npr_password'
});

// promises are [the] shit.
// we speak the way we breathe.
npr.one.init()
  .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 index.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.