<commit_before>var util = require('util');
var crypto = require('crypto');
var querystring = require('querystring');

var _ = {
  'forEach': require('lodash.foreach'),
  'assign': require('lodash.assign'),
  'partial': require('lodash.partial'),
};
var request = require('request');

var PublicClient = require('./public.js');


var AuthenticatedClient = function(key, b64secret, passphrase, apiURI) {
  var self = this;

  PublicClient.call(self, '', apiURI);
  self.key = key;
  self.b64secret = b64secret;
  self.passphrase = <PASSWORD>;
};

util.inherits(AuthenticatedClient, PublicClient);

_.assign(AuthenticatedClient.prototype, new function() {
  var prototype = this;

  prototype.request = function(method, uriParts, opts, callback) {
    var self = this;

    opts = opts || {};
    if (!callback && (opts instanceof Function)) {
      callback = opts;
      opts = {};
    }

    if (!callback) {
      throw "Must supply a callback"
    }

    var relativeURI = self.makeRelativeURI(uriParts);
    method = method.toUpperCase();
    _.assign(opts, {
      'method': method,
      'uri': self.makeAbsoluteURI(relativeURI)
    });

    self.addHeaders(opts, self._getSignature(method, relativeURI, opts));
    request(opts, self.makeRequestCallback(callback));
  };

  prototype._getSignature = function(method, relativeURI, opts) {
    var self = this;
    var body = '';

    if (opts.body) {
      body = JSON.stringify(opts.body);
    } else if (opts.qs && Object.keys(opts.qs).length !== 0) {
      body = '?' + querystring.stringify(opts.qs);
    }

    var timestamp = Date.now() / 1000;
    var what = timestamp + method + relativeURI + body;
    var key = Buffer(self.b64secret, 'base64');
    var hmac = crypto.createHmac('sha256', key);
    var signature = hmac.update(what).digest('base64');
    return {
      'CB-ACCESS-KEY': self.key,
      'CB-ACCESS-SIGN': signature,
      'CB-ACCESS-TIMESTAMP': timestamp,
      'CB-ACCESS-PASSPHRASE': self.passphrase,
    };
  };

  _.forEach(['get', 'post', 'put', 'delete'], function(method) {<commit_msg>setting request body to json string<commit_after>var util = require('util');
var crypto = require('crypto');
var querystring = require('querystring');

var _ = {
  'forEach': require('lodash.foreach'),
  'assign': require('lodash.assign'),
  'partial': require('lodash.partial'),
};
var request = require('request');

var PublicClient = require('./public.js');


var AuthenticatedClient = function(key, b64secret, passphrase, apiURI) {
  var self = this;

  PublicClient.call(self, '', apiURI);
  self.key = key;
  self.b64secret = b64secret;
  self.passphrase = <PASSWORD>;
};

util.inherits(AuthenticatedClient, PublicClient);

_.assign(AuthenticatedClient.prototype, new function() {
  var prototype = this;

  prototype.request = function(method, uriParts, opts, callback) {
    var self = this;

    opts = opts || {};
    if (!callback && (opts instanceof Function)) {
      callback = opts;
      opts = {};
    }

    if (!callback) {
      throw "Must supply a callback"
    }

    var relativeURI = self.makeRelativeURI(uriParts);
    method = method.toUpperCase();
    _.assign(opts, {
      'method': method,
      'uri': self.makeAbsoluteURI(relativeURI)
    });

    self.addHeaders(opts, self._getSignature(method, relativeURI, opts));
    request(opts, self.makeRequestCallback(callback));
  };

  prototype._getSignature = function(method, relativeURI, opts) {
    var self = this;
    var body = '';

    if (opts.body) {
      body = JSON.stringify(opts.body);
      opts.body = body;
    } else if (opts.qs && Object.keys(opts.qs).length !== 0) {
      body = '?' + querystring.stringify(opts.qs);
    }

    var timestamp = Date.now() / 1000;
    var what = timestamp + method + relativeURI + body;
    var key = Buffer(self.b64secret, 'base64');
    var hmac = crypto.createHmac('sha256', key);
    var signature = hmac.update(what).digest('base64');
    return {
      'CB-ACCESS-KEY': self.key,
      'CB-ACCESS-SIGN': signature,
      'CB-ACCESS-TIMESTAMP': timestamp,
      'CB-ACCESS-PASSPHRASE': self.passphrase,
    };
  };

  _.forEach(['get', 'post', 'put', 'delete'], function(method) {
{'fraction_non_alphanumeric': 0.15871121718377088, 'fraction_numerical': 0.00954653937947494, 'mean_word_length': 3.4585106382978723, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1049321', 'n_tokens_mistral': 1352, 'n_tokens_neox': 1293, 'n_words': 293}