<commit_before>var https  = require('https'),
    Q      = require('q'),
    config = require('../config.js');

/**
 * GitHub API client.
 * @returns {Object}
 */
var github = function () {
    // GitHub API endpoint.
    var ENDPOINT = 'api.github.com';

    // Request methods.
    var METHOD = {
        DELETE: 'DELETE',
        GET: 'GET',
        POST: 'POST',
        PUT: 'PUT'
    };

    /**
     * Calls the GitHub API.
     * @param {string} query
     * @param {string} method
     * @param {Object} data
     * @returns {promise}
     */
    var callApi = function (query, method, data) {
        var deferred = Q.defer(),
            resData = '';

        if (!method) {
            method = METHOD.GET;
        }

        var reqOptions = {
            method: method,
            host: ENDPOINT,
            path: query
        };

        if (data) {
            var dataJson = JSON.stringify(data);
            reqOptions.headers = {
                'Content-Type': 'application/json',
                'Content-Length': dataJson.length
            };
            console.log(method + ' https://' + ENDPOINT + query + ' ' + dataJson);
        } else {
            console.log(method + ' https://' + ENDPOINT + query);
        }

        var httpReq = https.request(reqOptions, function (httpRes) {
            httpRes.setEncoding('utf8');
            httpRes.on('data', function (chunk) {
                resData += chunk;
            });
            httpRes.on('end', function () {
                resData = JSON.parse(resData);
                deferred.resolve(resData);
            });
        });

        httpReq.on('error', function (err) {
            deferred.reject(err);
        });

        if (dataJson) {
            httpReq.write(dataJson);
        }<commit_msg>Add missing headers to the github client<commit_after>var https  = require('https'),
    Q      = require('q'),
    config = require('../config.js');

/**
 * GitHub API client.
 * @returns {Object}
 */
var github = function () {
    // GitHub API endpoint.
    var ENDPOINT = 'api.github.com';

    // Request methods.
    var METHOD = {
        DELETE: 'DELETE',
        GET: 'GET',
        POST: 'POST',
        PUT: 'PUT'
    };

    /**
     * Calls the GitHub API.
     * @param {string} query
     * @param {string} method
     * @param {Object} data
     * @returns {promise}
     */
    var callApi = function (query, method, data) {
        var deferred = Q.defer(),
            resData = '';

        if (!method) {
            method = METHOD.GET;
        }

        var reqOptions = {
            method: method,
            host: ENDPOINT,
            path: query,
            headers: {
                'User-Agent': 'hello-server',
                'Accept': 'application/json',
                'Content-Length': 0
            }
        };

        if (data) {
            var dataJson = JSON.stringify(data);
            reqOptions.headers['Content-Type'] = 'application/json';
            reqOptions.headers['Content-Length'] = dataJson.length;
            console.log(method + ' https://' + ENDPOINT + query + ' ' + dataJson);
        } else {
            console.log(method + ' https://' + ENDPOINT + query);
        }

        var httpReq = https.request(reqOptions, function (httpRes) {
            // todo: handle invalid requests
            httpRes.setEncoding('utf8');
            httpRes.on('data', function (chunk) {
                resData += chunk;
            });
            httpRes.on('end', function () {
                resData = JSON.parse(resData);
                deferred.resolve(resData);
            });
        });

        httpReq.on('error', function (err) {
            deferred.reject(err);
        });

        if (dataJson) {
            httpReq.write(dataJson);
        }
{'fraction_non_alphanumeric': 0.14162077104642015, 'fraction_numerical': 0.0007867820613690008, 'mean_word_length': 1.4702072538860103, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, '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': '7453331', 'n_tokens_mistral': 1097, 'n_tokens_neox': 1042, 'n_words': 242}