<commit_before>/**
 * MessageModel
 *
 * @return MessageModel
 * @author <NAME> <<EMAIL>>
 * @license MIT License
 * @see LICENSE
 */
define(['jquery', 'lib/extend', 'core/model', 'core/valuemodel'], function (
  $, extend, Model, ValueModel) {
  /**
   * Constructor
   */
  function MessageModel(server, apipath, data) {
    MessageModel.superconstructor.call(this);

    this.server = server;
    this.apipath = apipath;
    this.data = data;

    this.status = new ValueModel('unsent');
    this.result = new ValueModel(undefined);

    this.registerListener(this);
  }
  extend(MessageModel, Model);

  MessageModel.prototype.send = function() {
    if (this.server.tokenvalid.get() === false || !this.server.token.get()) {
      return false;
    }
    if (this.status.get() === 'sent') {
      return false;
    }
    this.result.set(undefined);

    this.server.registerMessage();

    $.ajax({
      method: 'POST',
      url: 'https://api.tuvero.de/' + this.apipath,
      data: 'auth=' + this.server.token.get(),
      timeout: 5000,
      success: (function(data) {
        this.result.set(data);
        if (!data || data.error) {
          this.status.set('error');
          this.emit('error', data);
        } else {
          this.status.set('done');
          this.emit('receive', data);
        }
      }).bind(this),
      error: (function(data) {
        this.result.set(data);
        this.status.set('error');
        this.emit('error', data);
      }).bind(this),
      complete: (function(data) {
        this.server.unregisterMessage();
        this.emit('complete', data);
      }).bind(this)
    });

    this.status.set('sent');
    this.emit('send', this.data);

    return true;
  };

  MessageModel.prototype.onsend = function(emitter, event, data) {
  };

  MessageModel.prototype.onreceive = function(emitter, event, data) {
  };

  MessageModel.prototype.onerror = function(emitter, event, data) {
  };

  MessageModel.prototype.oncomplete = function(emitter, event, data) {

  };

  MessageModel.prototype.EVENTS = {
    'error': true,
    'send': true,
    'receive': true,
    'complete': true
  };

  return MessageModel;
});<commit_msg>MessageModel: using Bearer token, sending data<commit_after>/**
 * MessageModel
 *
 * @return MessageModel
 * @author <NAME> <<EMAIL>>
 * @license MIT License
 * @see LICENSE
 */
define(['jquery', 'lib/extend', 'core/model', 'core/valuemodel'], function (
  $, extend, Model, ValueModel) {
  /**
   * Constructor
   */
  function MessageModel(server, apipath, data) {
    MessageModel.superconstructor.call(this);

    this.server = server;
    this.apipath = apipath;
    this.data = data;

    this.status = new ValueModel('unsent');
    this.result = new ValueModel(undefined);

    this.registerListener(this);
  }
  extend(MessageModel, Model);

  MessageModel.prototype.send = function () {
    var server = this.server;

    if (this.server.tokenvalid.get() === false || !this.server.token.get()) {
      return false;
    }
    if (this.status.get() === 'sent') {
      return false;
    }
    this.result.set(undefined);

    this.server.registerMessage();

    $.ajax({
      method: 'POST',
      url: 'https://api.tuvero.de/' + this.apipath,
      data: this.data,
      beforeSend: function (xhr) {
        xhr.setRequestHeader("Authorization", "Bearer " + server.token.get());
      },
      xhrFields: {
        withCredentials: true,
      },
      dataType: 'json',
      timeout: 10000,
      success: (function (data) {
        this.result.set(data);
        if (!data || data.error) {
          this.status.set('error');
          this.emit('error', data);
        } else {
          this.status.set('done');
          this.emit('receive', data);
        }
      }).bind(this),
      error: (function (data) {
        this.result.set(data);
        this.status.set('error');
        this.emit('error', data);
      }).bind(this),
      complete: (function (data) {
        this.server.unregisterMessage();
        this.emit('complete', data);
      }).bind(this)
    });

    this.status.set('sent');
    this.emit('send', this.data);

    return true;
  };

  MessageModel.prototype.onsend = function (emitter, event, data) {
  };

  MessageModel.prototype.onreceive = function (emitter, event, data) {
  };

  MessageModel.prototype.onerror = function (emitter, event, data) {
  };

  MessageModel.prototype.oncomplete = function (emitter, event, data) {

  };

  MessageModel.prototype.EVENTS = {
    'error': true,
    'send': true,
    'receive': true,
    'complete': true
  };

  return MessageModel;
});
{'fraction_non_alphanumeric': 0.16691990449316257, 'fraction_numerical': 0.0019535489472541786, 'mean_word_length': 2.634069400630915, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '5365327', 'n_tokens_mistral': 1481, 'n_tokens_neox': 1427, 'n_words': 277}