<commit_before>'use strict';
var log = require('debug')('coinbase'),
  microtime = require('microtime'),
  request = require('request'),
  util = require('util'),
  cryptoJS = require('crypto-js');

function CoinbaseError (error) {
  Error.captureStackTrace(this, CoinbaseError);
  this.error = error;
}

util.inherits(CoinbaseError, Error);

CoinbaseError.prototype.toString = function toString () {
  return "CoinbaseError: " + this.error;
}

var counter = 0, last = '';
function getNonce() {
  counter++;
  var nonce = microtime.now() + '' + (100 + counter % 100);
  if (nonce < last) {
    nonce = getNonce();
    last = nonce;
  } 
  return nonce;
}

function Coinbase (options) {
  if (!options || !options.APIKey || !options.APISecret)
    throw new CoinbaseError('Must provide an APIKey and APISecret in order to interact with the coinbase api');
  this.apiKey = options.APIKey;
  this.apiSecret = options.APISecret;
  this.baseUrl = 'https://coinbase.com/api/v1/';

  var self = this;

  this.account = {};

  function get (url, callback) {
    var nonce = getNonce();
    var message = nonce + url;
    var signature = cryptoJS.HmacSHA256(message, self.apiSecret);
    var reqObject = {
      url: url,
      headers: {
        'ACCESS_KEY': self.apiKey,
        'ACCESS_SIGNATURE': signature,
        'ACCESS_NONCE': nonce
      }
    }

    request.get(reqObject, function (err, res, data) {
      if (err) {
        return callback(err);
      } else {
        
        try {
          data = JSON.parse(data);
        } catch (err) {
          return callback(err);
        }

        if (data.success === false || data.errors || data.error) {
          return callback(new CoinbaseError(data.errors || data.error))
        } 
      
      }
      
      callback(null, data);
    });
  }

  function post (url, param, callback) {
    var nonce = getNonce();
    var body = JSON.stringify(param);
    var message = nonce + url + body;
    var signature = cryptoJS.HmacSHA256(message, self.apiSecret);
    var reqObject = {
      headers: {
        'ACCESS_KEY': self.apiKey,
        'ACCESS_SIGNATURE': signature,
        'ACCESS_NONCE': nonce,
        'content-type': 'application/json'
      },
      url: url,
      body: body
    };

    request.post(reqObject, function (err, res, data) {
      if (err) { return callback(err); }
      if (res.statusCode !== 200) return callback(new CoinbaseError(res.headers.status));
      try {
        data = JSON.parse(data);
      } catch (parseError) {
        return callback(parseError);
      }

      if (data.success === false) { return callback(new CoinbaseError(data.errors || data.error)); }
      if (data.errors) { return callback(new CoinbaseError(data.errors)); }
      
      callback(null, data);
    });
  }

  /* GET /api/v1/account/balance */
  this.account.balance = function (callback) {
    var url = self.baseUrl + 'account/balance';

    log('get ' + url);

    get(url, callback);
  };

  /* GET /api/v1/account/receive_address */
  this.account.receiveAddress = function (callback) {
    var url = self.baseUrl + 'account/receive_address';

    log('get ' + url);

    get(url, callback);
  };
<commit_msg>updated post to mirror get<commit_after>'use strict';
var log = require('debug')('coinbase'),
  microtime = require('microtime'),
  request = require('request'),
  util = require('util'),
  cryptoJS = require('crypto-js');

function CoinbaseError (error) {
  Error.captureStackTrace(this, CoinbaseError);
  this.error = error;
}

util.inherits(CoinbaseError, Error);

CoinbaseError.prototype.toString = function toString () {
  return "CoinbaseError: " + this.error;
}

var counter = 0, last = '';
function getNonce() {
  counter++;
  var nonce = microtime.now() + '' + (100 + counter % 100);
  if (nonce < last) {
    nonce = getNonce();
    last = nonce;
  } 
  return nonce;
}

function Coinbase (options) {
  if (!options || !options.APIKey || !options.APISecret)
    throw new CoinbaseError('Must provide an APIKey and APISecret in order to interact with the coinbase api');
  this.apiKey = options.APIKey;
  this.apiSecret = options.APISecret;
  this.baseUrl = 'https://coinbase.com/api/v1/';

  var self = this;

  this.account = {};

  function get (url, callback) {
    var nonce = getNonce();
    var message = nonce + url;
    var signature = cryptoJS.HmacSHA256(message, self.apiSecret);
    var reqObject = {
      url: url,
      headers: {
        'ACCESS_KEY': self.apiKey,
        'ACCESS_SIGNATURE': signature,
        'ACCESS_NONCE': nonce
      }
    }

    request.get(reqObject, function (err, res, data) {
      if (err) {
        return callback(err);
      } else {
        try {
          data = JSON.parse(data);
        } catch (err) {
          return callback(err);
        }
        if (data.success === false || data.errors || data.error) {
          return callback(new CoinbaseError(data.errors || data.error))
        } 
        return callback(null, data);
      }
      
    });
  }

  function post (url, param, callback) {
    var nonce = getNonce();
    var body = JSON.stringify(param);
    var message = nonce + url + body;
    var signature = cryptoJS.HmacSHA256(message, self.apiSecret);
    var reqObject = {
      headers: {
        'ACCESS_KEY': self.apiKey,
        'ACCESS_SIGNATURE': signature,
        'ACCESS_NONCE': nonce,
        'content-type': 'application/json'
      },
      url: url,
      body: body
    };

    request.post(reqObject, function (err, res, data) {
      if (err) { return callback(err); }
      try {
        data = JSON.parse(data);
      } catch (err) {
        return callback(err);
      }
      if (data.success === false || data.errors || data.error) {
        return callback(new CoinbaseError(data.errors || data.error))
      }
      return callback(null, data);
    });
  }

  /* GET /api/v1/account/balance */
  this.account.balance = function (callback) {
    var url = self.baseUrl + 'account/balance';

    log('get ' + url);

    get(url, callback);
  };

  /* GET /api/v1/account/receive_address */
  this.account.receiveAddress = function (callback) {
    var url = self.baseUrl + 'account/receive_address';

    log('get ' + url);

    get(url, callback);
  };

{'fraction_non_alphanumeric': 0.14233109189881524, 'fraction_numerical': 0.005603586295228946, 'mean_word_length': 2.592294422081656, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '2299122', 'n_tokens_mistral': 2037, 'n_tokens_neox': 1967, 'n_words': 465}