<commit_before>var request = require('request');

var Diffbot = exports.Diffbot =
    function(token) {
        if (!token) {
            throw new Error ('Authorization token is required');
        }
        this.token = token;
    };

/**
 * Sends request to API
 * @param {Object} params
 * @param {Object} [options]
 * @param {Function} callback
 * @private
 */
Diffbot.prototype._request = function(params, options, callback) {

    if (!params.url) {
        throw new Error('The URL is required');
    }

    var url = 'http://api.diffbot.com/v2/' + params.type +
        '?token=' + this.token +
        '&url=' + encodeURIComponent(params.url);

    request(url, function(error, response, body) {
        if (error) {
            callback(error);
        } else {
            callback(false, JSON.parse(body));
        }
    })

};<commit_msg>Added article method<commit_after>var request = require('request');

var Diffbot = exports.Diffbot =
    function(token) {
        if (!token) {
            throw new Error ('Authorization token is required');
        }
        this.token = token;
    };

/**
 * Sends request to API
 * @param {Object} params
 * @param {Object} [options]
 * @param {Function} callback
 * @private
 */
Diffbot.prototype._request = function(params, options, callback) {

    if (!params.url) {
        throw new Error('The URL is required');
    }

    var url = 'http://api.diffbot.com/v2/' + params.type +
        '?token=' + this.token +
        '&url=' + encodeURIComponent(params.url);

    for (var key in options) {
        url += '&' + key + '=' + options[key];
    }

    request(url, function(error, response, body) {
        if (error) {
            callback(error);
        } else {
            callback(false, JSON.parse(body));
        }
    })

};

/**
 * Fetches article
 * @param {String} url
 * @param {Object} [options], can have keys:
 *      {Array} fields,
 *      {Number} timeout
 * @param {Function} callback
 */
Diffbot.prototype.article = function(url, options, callback) {

    if (typeof options == 'function') {
        callback = options;
        options = {};
    }

    var params = {
        type: 'article',
        url: url
    };

    // TODO: validate options

    this._request(params, options, callback);

};
{'fraction_non_alphanumeric': 0.15030674846625766, 'fraction_numerical': 0.0008764241893076249, 'mean_word_length': 2.2614285714285716, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1927810', 'n_tokens_mistral': 685, 'n_tokens_neox': 677, 'n_words': 175}