<commit_before>var AdmZip = require('adm-zip');
var async = require('async');
var cheerio = require('cheerio');
var request = require('request');
var constants = require('./constants');

var CONTENT_API_BASE = constants.CONTENT_API_BASE;
var VIEW_API_BASE = constants.VIEW_API_BASE;
var LIMIT = 1000; // refer <https://developers.box.com/docs/#folders-retrieve-a-folders-items>

var OPTIONS = { normalizeWhitespace: true, xmlMode: true };

function retrieve(token, path, callback) {
  var name = 'box.retrieve()';
  var start = new Date();
  request.get({
    headers: { Authorization: "Bearer " +  token },
    url: CONTENT_API_BASE + path,
    json: true
  }, function(err, res, body) {
    if (err) {
      callback({ name: name, error: err });
      return;
    }
    if (res.statusCode !== 200) {
      callback({ name: name, status: res.statusCode, body: body });
      return;
    }
    callback(null, body);
    console.log(name + ' ' + (new Date() - start) + ' msec');
  });
}

function location(token, id, callback) {
  var name = 'box.location()';
  var start = new Date();
  request.get({
    headers: { Authorization: "Bearer " + token },
    url: CONTENT_API_BASE + '/files/' + id + '/content',
    followRedirect: false,
    json: true
  }, function(err, res) {
    if (err) {
      callback({ name: name, error: err });
      return;
    }
    if (res.statusCode !== 302) {
      callback({ name: name, status: res.statusCode });
      return;
    }
    callback(null, res.headers.location);
    console.log(name + ' ' + (new Date() - start) + ' msec');
  });
}

function upload(uri, id, callback) {
  var name = 'box.upload()';
  var start = new Date();
  var form = request.post({
    headers: { Authorization: "Token " + process.env.API_KEY },
    url: VIEW_API_BASE + '/documents',
    json: true
  }, function(err, res, body) {
    if (err) {
      callback({ name: name, error: err });
      return;
    }
    if (res.statusCode !== 202) {
      callback({ name: name, status: res.statusCode, body: body });
      return;
    }
    callback(null, body);
    console.log(name + ' ' + (new Date() - start) + ' msec');
  }).form();
  form.append('url', uri);
  form.append('name', id);
}

function documents(callback) {
  var name = 'box.sessions()';
  var start = new Date();
  request({
    headers: { Authorization: "Token " + process.env.API_KEY },
    url: VIEW_API_BASE + '/documents?limit=50',<commit_msg>Corrected  name value in documents() of lib/box.js.<commit_after>var AdmZip = require('adm-zip');
var async = require('async');
var cheerio = require('cheerio');
var request = require('request');
var constants = require('./constants');

var CONTENT_API_BASE = constants.CONTENT_API_BASE;
var VIEW_API_BASE = constants.VIEW_API_BASE;
var LIMIT = 1000; // refer <https://developers.box.com/docs/#folders-retrieve-a-folders-items>

var OPTIONS = { normalizeWhitespace: true, xmlMode: true };

function retrieve(token, path, callback) {
  var name = 'box.retrieve()';
  var start = new Date();
  request.get({
    headers: { Authorization: "Bearer " +  token },
    url: CONTENT_API_BASE + path,
    json: true
  }, function(err, res, body) {
    if (err) {
      callback({ name: name, error: err });
      return;
    }
    if (res.statusCode !== 200) {
      callback({ name: name, status: res.statusCode, body: body });
      return;
    }
    callback(null, body);
    console.log(name + ' ' + (new Date() - start) + ' msec');
  });
}

function location(token, id, callback) {
  var name = 'box.location()';
  var start = new Date();
  request.get({
    headers: { Authorization: "Bearer " + token },
    url: CONTENT_API_BASE + '/files/' + id + '/content',
    followRedirect: false,
    json: true
  }, function(err, res) {
    if (err) {
      callback({ name: name, error: err });
      return;
    }
    if (res.statusCode !== 302) {
      callback({ name: name, status: res.statusCode });
      return;
    }
    callback(null, res.headers.location);
    console.log(name + ' ' + (new Date() - start) + ' msec');
  });
}

function upload(uri, id, callback) {
  var name = 'box.upload()';
  var start = new Date();
  var form = request.post({
    headers: { Authorization: "Token " + process.env.API_KEY },
    url: VIEW_API_BASE + '/documents',
    json: true
  }, function(err, res, body) {
    if (err) {
      callback({ name: name, error: err });
      return;
    }
    if (res.statusCode !== 202) {
      callback({ name: name, status: res.statusCode, body: body });
      return;
    }
    callback(null, body);
    console.log(name + ' ' + (new Date() - start) + ' msec');
  }).form();
  form.append('url', uri);
  form.append('name', id);
}

function documents(callback) {
  var name = 'box.documents()';
  var start = new Date();
  request({
    headers: { Authorization: "Token " + process.env.API_KEY },
    url: VIEW_API_BASE + '/documents?limit=50',
{'fraction_non_alphanumeric': 0.17200571311977148, 'fraction_numerical': 0.006121199755152009, 'mean_word_length': 3.0815986677768525, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '6360053', 'n_tokens_mistral': 1669, 'n_tokens_neox': 1620, 'n_words': 419}