<commit_before>/**
 * io.SocketNamespace.prototype.*
 *
 * Additional functionality for the Sails.js framework
 * Extends Socket.io socket object with some convenience methods
 *
 */


 /**
 *
 * Simulate an HTTP request to the backend
 *   @param {String} url    ::    the request label (usually the destination URL)
 *   @param {Object} data   ::    data to pass with the request
 *   @param {Object} options::    optional callback or config object
 *   @param {String} method ::    HTTP method (aka verb)
 *
 *
 * Note:  This should really be a private method, but it is
 *        exposed for backwards compatibility with Sails 0.8.x.
 *        The preferred usage in Sails v0.9+ is verb-based; e.g.,
 *          *-> `connectedSocket.get()`
 *          *-> `connectedSocket.post()`
 *          *-> `connectedSocket.put()`
 *          *-> `connectedSocket.delete()`
 */

io.SocketNamespace.prototype.request = function (url, data, options, method) {

  // Remove trailing slashes and spaces
  url = url.replace(/\/*\s*$/, '');

  // If url is empty, use /
  if (url === '') url = '/';

  // If options is a function, treat it as a callback
  // Otherwise the "success" property will be treated as the callback
  var cb;
  if (typeof options === 'function') cb = options;
  else cb = options.success;

  var json = io.JSON.stringify({
    url: url,
    data: data,
    method: method || 'get'
  });

  this.emit('message', json, function (result) {

    var parsedResult = result
    try {
      parsedResult = io.JSON.parse(result);
    } catch (e) {
      if (typeof console !== 'undefined') {
        console.log("Could not parse:", result, e);
      }
      throw new Error("Server response could not be parsed!  " + result);
    }

    // TODO: Handle errors more effectively
    if (parsedResult === 404) throw new Error("404: Not found");
    if (parsedResult === 403) throw new Error("403: Forbidden");
    if (parsedResult === 500) throw new Error("500: Server error");

    cb(parsedResult);
  });
};
<commit_msg>added socket get, post, put, and delete functions client side<commit_after>/**
 * io.SocketNamespace.prototype.*
 *
 * Additional functionality for the Sails.js framework
 * Extends Socket.io socket object with some convenience methods
 *
 */


 /**
 *
 * Simulate an HTTP request to the backend
 *   @param {String} url    ::    the request label (usually the destination URL)
 *   @param {Object} data   ::    data to pass with the request
 *   @param {Object} options::    optional callback or config object
 *   @param {String} method ::    HTTP method (aka verb)
 *
 *
 * Note:  This should really be a private method, but it is
 *        exposed for backwards compatibility with Sails 0.8.x.
 *        The preferred usage in Sails v0.9+ is verb-based; e.g.,
 *          *-> `connectedSocket.get()`
 *          *-> `connectedSocket.post()`
 *          *-> `connectedSocket.put()`
 *          *-> `connectedSocket.delete()`
 */

io.SocketNamespace.prototype.request = function (url, data, options, method) {

  // Remove trailing slashes and spaces
  url = url.replace(/\/*\s*$/, '');

  // If url is empty, use /
  if (url === '') url = '/';

  // If options is a function, treat it as a callback
  // Otherwise the "success" property will be treated as the callback
  var cb;
  if (typeof options === 'function') cb = options;
  else cb = options.success;

  var json = io.JSON.stringify({
    url: url,
    data: data
  });

  this.emit(method || 'get', json, function (result) {

    var parsedResult = result
    try {
      parsedResult = io.JSON.parse(result);
    } catch (e) {
      if (typeof console !== 'undefined') {
        console.log("Could not parse:", result, e);
      }
      throw new Error("Server response could not be parsed!  " + result);
    }

    // TODO: Handle errors more effectively
    if (parsedResult === 404) throw new Error("404: Not found");
    if (parsedResult === 403) throw new Error("403: Forbidden");
    if (parsedResult === 500) throw new Error("500: Server error");

    cb(parsedResult);
  });
};

io.SocketNamespace.prototype.get = function(url, data, options){
  return this.request(url, data, options, 'get');
}

io.SocketNamespace.prototype.post = function(url, data, options){
  return this.request(url, data, options, 'post');
}

io.SocketNamespace.prototype.put = function(url, data, options){
  return this.request(url, data, options, 'put');
}

io.SocketNamespace.prototype.delete = function(url, data, options){
  return this.request(url, data, options, 'delete');
}
{'fraction_non_alphanumeric': 0.1390597539543058, 'fraction_numerical': 0.009666080843585237, 'mean_word_length': 2.9081545064377683, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '2749833', 'n_tokens_mistral': 1361, 'n_tokens_neox': 1310, 'n_words': 461}