hack-news
Advanced tools
Comparing version 2.0.3 to 2.0.4
24
index.js
@@ -221,1 +221,25 @@ const https = require('https'); | ||
} | ||
//get all changed items and profiles | ||
exports.changedItemsAndProfiles = function (callback) { | ||
callback = callback || () => {}; | ||
return new Promise((resolve, reject) => { | ||
https.get('https://hacker-news.firebaseio.com/v0/updates.json?print=pretty', (res) => { | ||
res.on('data', (d) => { | ||
const stories = JSON.parse(d, (key, value) => { | ||
return value && value.type === 'Buffer' | ||
? new Buffer(value.data) | ||
: value; | ||
}); | ||
resolve(stories); | ||
callback(null, stories); | ||
}); | ||
}).on('error', (e) => { | ||
reject(e); | ||
callback(e, null); | ||
}); | ||
}); | ||
} |
{ | ||
"name": "hack-news", | ||
"version": "2.0.3", | ||
"version": "2.0.4", | ||
"description": "A simple library of methods to help you interact with the Hacker News API. There's more on the way.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -198,2 +198,20 @@ ## Installation | ||
####Changed items and profiles | ||
The examples below show how to access the changed or updated items and profiles on Hacker News. | ||
```javascript | ||
var hn = require('hack-news'); | ||
//This will return a object with two properties, one for the items and another for the profiles. | ||
hn.changedItemsAndProfiles( (error, itemsProfiles) => { | ||
if (error) { | ||
console.log(error); | ||
} | ||
console.log(itemsProfiles); | ||
}); | ||
//Using Promises | ||
hn.changedItemsAndProfiles().then(itemsProfiles => {console.log(itemsProfiles);}); | ||
``` | ||
This is it for now but stay tuned I will be adding a lot more. |
13899
202
217