<commit_before>'use strict';

var util = require('util'),
  Config = require('./Config'),
  DataStore = require('./ds/DataStore'),
  Tenant = require('./resource/Tenant');

function Client(config) {
  this.config = new Config(config);
  if(!this.config.apiKey){
    this.config.apiKey = this.config.client.apiKey;
  }
  this._dataStore = new DataStore(this.config);

  this._currentTenant = null; //we'll be able to cache this on first call
}
util.inherits(Client, Object);

Client.prototype.getCurrentTenant = function getCurrentTenant(/* [options,] callback */) {
  var self = this;
  var args = Array.prototype.slice.call(arguments);
  var callback = args.pop();
  var options = (args.length > 0) ? args.shift() : null;

  //check to see if cached (tenant never changes for a given API Key):
  if (self._currentTenant) {
    return callback(null, self._currentTenant);
  }

  //not cached - need to look it up (and cache it):
  return self._dataStore.getResource('/tenants/current', options, Tenant, function onCurrentTenant(err, tenant) {
    if (err) {
      return callback(err, null);
    }

    self._currentTenant = tenant;
    return callback(null, tenant);
  });
};
<commit_msg>Making our Client object an event emitter =)<commit_after>'use strict';

var events = require('events'),
  util = require('util'),
  Config = require('./Config'),
  DataStore = require('./ds/DataStore'),
  Tenant = require('./resource/Tenant');

function Client(config) {
  events.EventEmitter.call(this);

  this.config = new Config(config);
  if(!this.config.apiKey){
    this.config.apiKey = this.config.client.apiKey;
  }
  this._dataStore = new DataStore(this.config);

  this._currentTenant = null; //we'll be able to cache this on first call
}

util.inherits(Client, Object);
util.inherits(Client, events.EventEmitter);

Client.prototype.getCurrentTenant = function getCurrentTenant(/* [options,] callback */) {
  var self = this;
  var args = Array.prototype.slice.call(arguments);
  var callback = args.pop();
  var options = (args.length > 0) ? args.shift() : null;

  //check to see if cached (tenant never changes for a given API Key):
  if (self._currentTenant) {
    return callback(null, self._currentTenant);
  }

  //not cached - need to look it up (and cache it):
  return self._dataStore.getResource('/tenants/current', options, Tenant, function onCurrentTenant(err, tenant) {
    if (err) {
      return callback(err, null);
    }

    self._currentTenant = tenant;
    return callback(null, tenant);
  });
};

{'fraction_non_alphanumeric': 0.14331083763398175, 'fraction_numerical': 0.0007939658594680428, 'mean_word_length': 3.864864864864865, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3163486', 'n_tokens_mistral': 785, 'n_tokens_neox': 774, 'n_words': 212}