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

// Globals
var API_URL = 'https://unbabel.com/tapi/v2/',
    SANDBOX_API_URL = 'http://sandbox.unbabel.com/tapi/v2/';

////
//   REQUEST HANDLERS
////

var createMethod = function(method, username, privateKey, sandbox) {
  return function(uri, data, cb) {
    if (typeof data === 'function') {
      cb = data;
      data = {};
    } else if (['string', 'number'].indexOf(typeof data) !== -1) {
      data = { id: data };
    }
    
    var options = {
      method: method,
      uri: (sandbox ? SANDBOX_API_URL : API_URL) + uri,
      headers: { 
        Accept: 'application/json',
        Authorization: 'ApiKey ' + username + ':' + privateKey
      }
    };
    //If no params in URL, close with /
    if(options.uri.indexOf('?') === -1) options.uri += '/';
    
    // Add data to request
    if (method === 'GET' || method === 'DELETE') options.qs = data || {};
    else options.body = JSON.stringify(data) || {};

    request(options, globalResponseHandler(cb));
  };
};

////
//   RESPONSE HANDLERS
////

var globalResponseHandler = function(cb) {
  return function(err, res, body) {
    if (typeof cb !== 'function') return;

    // Catch connection errors
    if (err || !res) {
      var returnErr = 'Error connecting to Unbabel';
      if (err) returnErr += ': ' + err.code;
      err = returnErr;<commit_msg>Add Content-Type to request<commit_after>var request         = require('request');

// Globals
var API_URL = 'https://unbabel.com/tapi/v2/',
    SANDBOX_API_URL = 'http://sandbox.unbabel.com/tapi/v2/';

////
//   REQUEST HANDLERS
////

var createMethod = function(method, username, privateKey, sandbox) {
  return function(uri, data, cb) {
    if (typeof data === 'function') {
      cb = data;
      data = {};
    } else if (['string', 'number'].indexOf(typeof data) !== -1) {
      data = { id: data };
    }
    
    var options = {
      method: method,
      uri: (sandbox ? SANDBOX_API_URL : API_URL) + uri,
      headers: { 
        Accept: 'application/json',
        'Content-Type': 'application/json',
        Authorization: 'ApiKey ' + username + ':' + privateKey
      }
    };
    //If no params in URL, close with /
    if(options.uri.indexOf('?') === -1) options.uri += '/';
    
    // Add data to request
    if (method === 'GET' || method === 'DELETE') options.qs = data || {};
    else options.body = JSON.stringify(data) || {};

    request(options, globalResponseHandler(cb));
  };
};

////
//   RESPONSE HANDLERS
////

var globalResponseHandler = function(cb) {
  return function(err, res, body) {
    if (typeof cb !== 'function') return;

    // Catch connection errors
    if (err || !res) {
      var returnErr = 'Error connecting to Unbabel';
      if (err) returnErr += ': ' + err.code;
      err = returnErr;
{'fraction_non_alphanumeric': 0.17494677075940382, 'fraction_numerical': 0.0028388928317956, 'mean_word_length': 2.425273390036452, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2581462', 'n_tokens_mistral': 942, 'n_tokens_neox': 906, 'n_words': 226}