Skip to content

Instantly share code, notes, and snippets.

@L8D

L8D/diffbot.js

Last active Jan 1, 2016
Embed
What would you like to do?
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
You can’t perform that action at this time.