adds more usage details to the README

This commit is contained in:
Todd Treece 2015-08-02 10:11:19 -04:00
parent 98af3da547
commit 3f9049f1f0
2 changed files with 28 additions and 11 deletions

View file

@ -21,40 +21,56 @@ $ npm install npr-api
## Usage
As of right now, the full NPR One API is available in this package. There
are more examples in the `test` directory.
As of right now, the full [NPR One API](http://dev.npr.org/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'](http://www.npr.org/templates/apidoc/)
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.
**Example:** getting recommendations for your user
```
// paste into a file called index.js,
// and edit the credentials to match
// your 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: 'your_username',
password: 'your_password'
username: 'npr_username',
password: 'npr_password'
});
// promises are [the] shit.
// we speak the way we breathe.
npr.one.init()
.then(npr.one.listening.getRecommendations({ channel: 'npr' }))
.then(function(recommendations) {
console.log(recommendations);
// print out the first two recommendations to the console
console.log(recommendations.items.slice(0,2));
}).catch(console.err);
```
Then you can run this example by running:
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](http://dev.npr.org/api/).
More information about the NPR One API can be found at the [NPR One Developer Center](http://dev.npr.org/).
* Authorization
* `npr.one.authorization.createToken()`

View file

@ -23,6 +23,7 @@ function One(config) {
this.credentials.grant_type = 'password';
this.getAccessToken = this.getAccessToken.bind(this);
}
/*************************** DEFAULTS *****************************/