Skip to content

Instantly share code, notes, and snippets.

@L8D
Last active January 1, 2016 23:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save L8D/8216042 to your computer and use it in GitHub Desktop.
Save L8D/8216042 to your computer and use it in GitHub Desktop.
DiffBot article API for Node
var querystring = require('querystring'),
util = require('util'),
request = require('request');
var ARTICLE_URL = 'http://api.diffbot.com/v2/article';
exports.article = function(url, token, cb, options) {
options = options || {};
if (!url || !token || !cb) throw TypeError('3 arguments required.');
options.url = url;
options.token = token;
var query = querystring.stringify(options);
request(ARTICLE_URL + query, function(err, res, body) {
if (err) return cb(err);
// handle syntax errors in the JSON
var data;
try {
data = JSON.parse(body);
} catch (e) {
cb(e);
}
cb(null, data);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment