<commit_before>
/*!
  NodeJS GitHub API (v3) Wrapper
  @author <NAME>
*/

module.exports = github3 = function(){};

// Mikeal's http.request wrapper
var request = require('request');

github3.username = '';
github3.password = '';

/*!
  Sets credentials for GitHub access.
  @param {String} username GitHub username
  @param {String} password GitHub password
*/

github3.setCredentials = function(username,password) {
  this.username = username;
  this.password = password;
};

/*!
  Builds and executes a github api call
  @param {Object} options or just API URI Path for GET requests
  @param {Function} callback Function to call upon error or success
  @returns {Object} error, {Object} data
*/

github3._request = function (options,callback) {
  if (this.username && this.password) {
    // if we have credentials, use them in request
    base = 'https://'+this.username+':'+this.password+'@api.github.com';
  }
  else {
    base = 'https://api.github.com';
  }
  if (typeof(options) != "string") {
    options.path = base + options.path
  }
  else {
    options = base + options
  }
  
  request(options, function(error, response, body) {
    if (error) {
      callback(error, null);
    } else {
      switch(response.statusCode) {
        case 404:
          callback(new Error('Path not found'), null);
          break;
        default:
          try {
            var data = JSON.parse(body);
            callback(null, data);
          } catch (error) {
            callback(error, null);
          };
      };
    };
  });
};

github3._get = function(path, callback) {
  this._request(path,callback);
};

github3._put = function(path, body, callback) {
  var 
    body = (typeof(body)=="undefined"?body:'{}')
  this._request({
    path:path,
    method:"PUT",
    headers: {
      "Content-Length":body.length
    },
    body:body
  },
  callback);
}

/*
  Users
  @class github3
  @method getUser
*/

github3.getUser = function(user, callback){
  this._get('/users/' + user, callback);
};

/*
  User's Repos
  @class github3
  @method getUserRepos<commit_msg>path -> uri options hash fix<commit_after>
/*!
  NodeJS GitHub API (v3) Wrapper
  @author <NAME>
*/

module.exports = github3 = function(){};

// Mikeal's http.request wrapper
var request = require('request');

github3.username = '';
github3.password = '';

/*!
  Sets credentials for GitHub access.
  @param {String} username GitHub username
  @param {String} password GitHub password
*/

github3.setCredentials = function(username,password) {
  this.username = username;
  this.password = password;
};

/*!
  Builds and executes a github api call
  @param {Object} options or just API URI Path for GET requests
  @param {Function} callback Function to call upon error or success
  @returns {Object} error, {Object} data
*/

github3._request = function (options,callback) {
  if (this.username && this.password) {
    // if we have credentials, use them in request
    base = 'https://'+this.username+':'+this.password+'@api.github.com';
  }
  else {
    base = 'https://api.github.com';
  }
  if (typeof(options) != "string") {
    options.uri = base + options.uri
  }
  else {
    options = base + options
  }
  request(options, function(error, response, body) {
    if (error) {
      callback(error, null);
    } else {
      switch(response.statusCode) {
        case 404:
          callback(new Error('Path not found'), null);
          break;
        default:
          try {
            var data = JSON.parse(body);
            callback(null, data);
          } catch (error) {
            callback(error, null);
          };
      };
    };
  });
};

github3._get = function(path, callback) {
  this._request(path,callback);
};

github3._put = function(path, body, callback) {
  var 
    body = body || '{}'
  this._request({
    uri:path,
    method:"PUT",
    headers: {
      "Content-Length":body.length
    },
    body:body
  },
  callback);
}

/*
  Users
  @class github3
  @method getUser
*/

github3.getUser = function(user, callback){
  this._get('/users/' + user, callback);
};

/*
  User's Repos
  @class github3
  @method getUserRepos
{'fraction_non_alphanumeric': 0.1434108527131783, 'fraction_numerical': 0.006782945736434108, 'mean_word_length': 2.7673357664233578, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 6, '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': '1918535', 'n_tokens_mistral': 1304, 'n_tokens_neox': 1277, 'n_words': 335}