output recommended stories in index.js example
This commit is contained in:
parent
4366bd1384
commit
7955b1ad6b
1 changed files with 20 additions and 6 deletions
26
index.js
26
index.js
|
|
@ -1,6 +1,7 @@
|
|||
require('dotenv').load();
|
||||
|
||||
var API = require('./lib/api');
|
||||
var API = require('./lib/api'),
|
||||
fs = require('fs');
|
||||
|
||||
var NPR = API({
|
||||
client_id: process.env.CLIENT_ID,
|
||||
|
|
@ -9,11 +10,24 @@ var NPR = API({
|
|||
password: process.env.NPR_PASSWORD
|
||||
});
|
||||
|
||||
NPR.authenticate(function(token) {
|
||||
var logo = fs.readFileSync('./logo.txt', 'utf8');
|
||||
|
||||
if(! token)
|
||||
return console.error('invalid token');
|
||||
console.log(logo);
|
||||
|
||||
console.log('Bearer ' + token);
|
||||
console.log('----------------------------------------');
|
||||
console.log('FETCHING THE FIRST 5 RECOMMENDED STORIES');
|
||||
console.log('----------------------------------------');
|
||||
|
||||
});
|
||||
NPR.getAccessToken()
|
||||
.then(NPR.getRecommendations.bind(NPR, 'npr'))
|
||||
.then(function(recommendations) {
|
||||
// limit to the first 5
|
||||
recommendations = recommendations.slice(0,5)
|
||||
// dump each link to the console
|
||||
recommendations.forEach(function(link) {
|
||||
console.log(link, '\n');
|
||||
});
|
||||
})
|
||||
.catch(function(err) {
|
||||
console.error(err);
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue