<commit_before>var events  = require('events')
  , request = require('request')
  , async   = require('async')
  , _       = require('underscore')._
  , OAuth2  = require('./oauth2')
  , Query   = require('./query')
  , SObject = require('./sobject')
  ;

/**
 * constructor
 */
var Connection = module.exports = function(options) {
  this.initialize(options || {});
};

/**
 *
 */
Connection.prototype = new events.EventEmitter();

var loginUrl = "https://login.salesforce.com"
  , instanceUrl = "https://{instance}.salesforce.com"
  , version  = "23.0"
  ;

/**
 * initialize
 */
Connection.prototype.initialize = function(options) {
  this.loginUrl  = options.loginUrl || this.loginUrl || loginUrl;
  this.version   = options.version || this.version || version;
  this.instanceUrl = options.instanceUrl || options.serverUrl || this.instanceUrl || 
                     instanceUrl.replace("{instance}", options.instance || "na1");
  this.urls = {
    soap : {
      login : [ this.loginUrl, "services/Soap/u", this.version ].join('/')
    },
    rest : {
      base : [ this.instanceUrl, "services/data", "v" + this.version ].join('/')
    },
    streaming: {
      base : [ this.instanceUrl, "cometd", this.version ].join('/')
    }
  };
  if (options.clientId) {
    this.oauth2 = new OAuth2({
      authzServiceUrl : this.loginUrl + "/services/oauth2/authorize",
      tokenServiceUrl : this.loginUrl + "/services/oauth2/token",
      clientId : options.clientId,
      clientSecret : options.clientSecret,
      redirectUri : options.redirectUri
    });
  }
  this.accessToken = options.sessionId || options.accessToken || this.accessToken;
  this.refreshToken = options.refreshToken || this.refreshToken;
  this.maxRequest = options.maxRequest || this.maxRequest || 10;
};


/**
 * Sending request to API endpoint
 * @private
 */
Connection.prototype._request = function(params, callback, noContentResponse) {
  var self = this;
  var onResume = function(err) {
    if (err) {
      callback(err);
      return;
    }
    self._request(params, callback, noContentResponse); 
  };<commit_msg>raise error when client configuration is invalid<commit_after>var events  = require('events')
  , request = require('request')
  , async   = require('async')
  , _       = require('underscore')._
  , OAuth2  = require('./oauth2')
  , Query   = require('./query')
  , SObject = require('./sobject')
  ;

/**
 * constructor
 */
var Connection = module.exports = function(options) {
  this.initialize(options || {});
};

/**
 *
 */
Connection.prototype = new events.EventEmitter();

var loginUrl = "https://login.salesforce.com"
  , instanceUrl = "https://{instance}.salesforce.com"
  , version  = "23.0"
  ;

/**
 * initialize
 */
Connection.prototype.initialize = function(options) {
  this.loginUrl  = options.loginUrl || this.loginUrl || loginUrl;
  this.version   = options.version || this.version || version;
  this.instanceUrl = options.instanceUrl || options.serverUrl || this.instanceUrl || 
                     instanceUrl.replace("{instance}", options.instance || "na1");
  this.urls = {
    soap : {
      login : [ this.loginUrl, "services/Soap/u", this.version ].join('/')
    },
    rest : {
      base : [ this.instanceUrl, "services/data", "v" + this.version ].join('/')
    },
    streaming: {
      base : [ this.instanceUrl, "cometd", this.version ].join('/')
    }
  };
  if (options.clientId) {
    this.oauth2 = new OAuth2({
      authzServiceUrl : this.loginUrl + "/services/oauth2/authorize",
      tokenServiceUrl : this.loginUrl + "/services/oauth2/token",
      clientId : options.clientId,
      clientSecret : options.clientSecret,
      redirectUri : options.redirectUri
    });
  }
  this.accessToken = options.sessionId || options.accessToken || this.accessToken;
  this.refreshToken = options.refreshToken || this.refreshToken;
  if (this.refreshToken && !this.oauth2) {
    throw new Error("Refersh token is specified without oauth2 client information");
  }
  this.maxRequest = options.maxRequest || this.maxRequest || 10;
};


/**
 * Sending request to API endpoint
 * @private
 */
Connection.prototype._request = function(params, callback, noContentResponse) {
  var self = this;
  var onResume = function(err) {
    if (err) {
      callback(err);
      return;
    }
    self._request(params, callback, noContentResponse); 
  };
{'fraction_non_alphanumeric': 0.15761741122565864, 'fraction_numerical': 0.005956471935853379, 'mean_word_length': 3.162059103908484, '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': '4579675', 'n_tokens_mistral': 1350, 'n_tokens_neox': 1335, 'n_words': 257}