Last active
January 1, 2016 23:19
-
-
Save L8D/8216042 to your computer and use it in GitHub Desktop.
DiffBot article API for Node
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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