<commit_before>/**
 * Creates Q-wrapped request
 * See: https://github.com/request/request
 * User: motorro
 * Date: 15.01.2015
 * Time: 8:06
 */

"use strict";

var Q = require ("q");
var request = require("request");

/**
 * A list of methods to create denodeified versions
 * @type {string[]}
 */
var REQUEST_METHODS = [
    "del",
    "delete",
    "get",
    "head",
    "patch",
    "post",
    "put"
];

/**
 * Q-wrapped request constructor
 * @param {Object} [defaults] Default values
 * @constructor
 */
function QRequest(defaults) {

    if (null == defaults) defaults = QRequest.defaults;
    /**
     * The raw request object with optional defaults
     */
    this.raw = request.defaults(defaults);
}

QRequest.defaults = {};

// Create denodeified methods for request shortcuts
REQUEST_METHODS.forEach(function(method) {
    QRequest.prototype[method] = function () {
        var result = Q.defer();
        var fArgs = Array.prototype.slice.call(arguments, 0);
        fArgs.push(function (err, response, body) {
            if (null != err) {
                result.reject({ data: err });
            } else if(response.statusCode < 200 || response.statusCode >= 400) {
                result.reject({ data: body, statusCode: response.statusCode });
            } else {
                result.resolve({ data: body });
            }
        });
        this.raw[method].apply(this.raw, fArgs);
        return result.promise;
    };

    QRequest[method] = function() {
        var request = new QRequest(this.defaults);
        var args = Array.prototype.slice.call(arguments, 0);
        if ((method == 'post' || method == 'put') && (typeof args[1] == 'object')) {
            args[1] = { json: args[1] };
        } 
        return request[method].apply(request, args);
    }
});
<commit_msg>Renamed delete request method to del in q-request.js<commit_after>/**
 * Creates Q-wrapped request
 * See: https://github.com/request/request
 * User: motorro
 * Date: 15.01.2015
 * Time: 8:06
 */

"use strict";

var Q = require ("q");
var request = require("request");

/**
 * A list of methods to create denodeified versions
 * @type {string[]}
 */
var REQUEST_METHODS = [
    "del",
    "delete",
    "get",
    "head",
    "patch",
    "post",
    "put"
];

/**
 * Q-wrapped request constructor
 * @param {Object} [defaults] Default values
 * @constructor
 */
function QRequest(defaults) {

    if (null == defaults) defaults = QRequest.defaults;
    /**
     * The raw request object with optional defaults
     */
    this.raw = request.defaults(defaults);
}

QRequest.defaults = {};

// Create denodeified methods for request shortcuts
REQUEST_METHODS.forEach(function(method) {
    QRequest.prototype[method] = function () {
        var result = Q.defer();
        var fArgs = Array.prototype.slice.call(arguments, 0);
        fArgs.push(function (err, response, body) {
            if (null != err) {
                result.reject({ data: err });
            } else if(response.statusCode < 200 || response.statusCode >= 400) {
                result.reject({ data: body, statusCode: response.statusCode });
            } else {
                result.resolve({ data: body });
            }
        });
        if (method == 'delete') method = 'del';
        this.raw[method].apply(this.raw, fArgs);
        return result.promise;
    };

    QRequest[method] = function() {
        var request = new QRequest(this.defaults);
        var args = Array.prototype.slice.call(arguments, 0);
        if ((method == 'post' || method == 'put') && (typeof args[1] == 'object')) {
            args[1] = { json: args[1] };
        } 
        return request[method].apply(request, args);
    }
});

{'fraction_non_alphanumeric': 0.15384615384615385, 'fraction_numerical': 0.011875843454790824, 'mean_word_length': 2.403122130394858, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '2635930', 'n_tokens_mistral': 1138, 'n_tokens_neox': 1088, 'n_words': 280}