<commit_before>// Node modules
var https = require('https'),
  url = require('url');
  fs = require('fs');

// EdgeGrid Auth Module
var auth = require('./auth'),
  logger = require('./logger');

var _client_token = null,
  _client_secret = null,
  _access_token = null,
  _base_uri = null,
  _request = null;

function parseEdgerc(path, conf) {
  var edgerc = fs.readFileSync(path).toString().split("\n");
  var confData = [];
  for(var i=0;i<edgerc.length;i++) {
    var matchConf = edgerc[i].match(/\[(.*)\]/);
    // if we found our matching config, push the next 4 lines into a temp array
    if (matchConf && matchConf[1] === conf) {
      confData.push(edgerc[i+1]);
      confData.push(edgerc[i+2]);
      confData.push(edgerc[i+3]);
      confData.push(edgerc[i+4]);
      // convert the array to a descriptive object
      confData = confData.map(function(el) {
        var ret = {}
        var key = el.split(' = ')[0].trim();
        var val = el.split(' = ')[1].trim();
        if (key === 'host') {
          val = 'https://' + val;
        }
        ret[key] = val;
        return ret;
      });
      // turn the array of objects into a single object
      var result = {};
      for (var i = 0, length = confData.length; i < length; i++) {
        result[Object.keys(confData[i])[0]] = confData[i][Object.keys(confData[i])[0]];
      }
      return result;
    }
  }
  // if we escaped the parse loop without returning, something is wrong
  throw('An error occurred parsing the .edgerc file. You probably specified an invalid group name.');
}

var EdgeGrid = function(client_token, client_secret, access_token, base_uri) {
  // accepting an object containing a path to .edgerc and a config group
  if (typeof arguments[0] === 'object') {
    var path = arguments[0].path;
    var group = arguments[0].group;
    if (path === undefined) {
      logger.error("No .edgerc path");
      return false;
    }
    if (group === undefined) {
      logger.info("No .edgerc group provided, using 'default'");
      group = 'default';
    }
    var config = parseEdgerc(path, group);
    _client_token = config.client_token;
    _client_secret = config.client_secret;
    _access_token = config.access_token;
    _base_uri = config.host;
  }
  else {
    if (client_token === undefined || client_token === null) {
      logger.error("No client token");
      return false;
    } else if (client_secret === undefined || client_secret === null) {<commit_msg>api now using edgerc module<commit_after>// Node modules
var https = require('https'),
  url = require('url');
  fs = require('fs');

// EdgeGrid Auth Module
var auth = require('./auth'),
  edgerc = require('./edgerc'),
  logger = require('./logger');

var _client_token = null,
  _client_secret = null,
  _access_token = null,
  _base_uri = null,
  _request = null;

var EdgeGrid = function(client_token, client_secret, access_token, base_uri) {
  // accepting an object containing a path to .edgerc and a config group
  if (typeof arguments[0] === 'object') {
    var path = arguments[0].path;
    var group = arguments[0].group;
    if (path === undefined) {
      logger.error("No .edgerc path");
      return false;
    }

    var config = edgerc(path, group);
    _client_token = config.client_token;
    _client_secret = config.client_secret;
    _access_token = config.access_token;
    _base_uri = config.host;
  }
  else {
    if (client_token === undefined || client_token === null) {
      logger.error("No client token");
      return false;
    } else if (client_secret === undefined || client_secret === null) {
{'fraction_non_alphanumeric': 0.14691943127962084, 'fraction_numerical': 0.005018120992472818, 'mean_word_length': 2.986666666666667, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 1, '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': '2695872', 'n_tokens_mistral': 1139, 'n_tokens_neox': 1131, 'n_words': 319}