<commit_before>'use strict';

var rest = require('restler');
var Promise = require('bluebird');

function Request(taxjar) {
  this._taxjar = taxjar;
}

Request.prototype = {
  api: function(options) {
    var defer = Promise.defer();

    options.headers = options.headers || {};
    options.headers['Content-Type'] = 'application/json';

    rest[options.method](this._taxjar.getApiConfig('host') + options.url, {
      accessToken: this._taxjar.getApiConfig('key'),
      headers: options.headers,
      data: JSON.stringify(options.data),
      query: options.query
    }).on('complete', function(result) {
      if (result.error) {
        defer.reject(result);
      } else {
        defer.resolve(result);
      }
    });

    return defer.promise;
  }
};

module.exports = Request;<commit_msg>fixed Promise.defer() deprecated, fixes issue #6<commit_after>'use strict';

var rest = require('restler');
var Promise = require('bluebird');

function Request(taxjar) {
  this._taxjar = taxjar;
}

Request.prototype = {
  api: function(options) {
    var self = this;

    return new Promise(function(resolve, reject) {
      options.headers = options.headers || {};
      options.headers['Content-Type'] = 'application/json';

      rest[options.method](self._taxjar.getApiConfig('host') + options.url, {
        accessToken: self._taxjar.getApiConfig('key'),
        headers: options.headers,
        data: JSON.stringify(options.data),
        query: options.query
      }).on('complete', function(result) {
        if (result.error){
          reject(result);
        } else {
          resolve(result);
        }
      });
    });
  }
};

module.exports = Request;
{'fraction_non_alphanumeric': 0.1532934131736527, 'fraction_numerical': 0.0005988023952095808, 'mean_word_length': 3.0265060240963857, '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': '4076906', 'n_tokens_mistral': 503, 'n_tokens_neox': 490, 'n_words': 92}