<commit_before>jQuery.support.cors = true

@Travis.ajax = Em.Object.create
  DEFAULT_OPTIONS:
    accepts:
      json: 'application/vnd.travis-ci.2+json'

  get: (url, callback) ->
    @ajax(url, 'get', success: callback)

  post: (url, data, callback) ->
    @ajax(url, 'post', data: data, success: callback)

  ajax: (url, method, options) ->
    method = method.toUpperCase()
    endpoint = Travis.config.api_endpoint || ''
    options = options || {}

    if token = Travis.sessionStorage.getItem('travis.token')
      options.headers ||= {}
      options.headers['Authorization'] ||= "token #{token}"

    options.url = "#{endpoint}#{url}"
    options.type = method
    options.dataType = options.dataType || 'json'
    options.context = this

    if options.data && method != 'GET'
      options.data = JSON.stringify(options.data)

    if method != 'GET' && method != 'HEAD'
      options.contentType = options.contentType || 'application/json; charset=utf-8'

    success = options.success || (->)
    options.success = (data) =>
      Travis.app.router.flashController.loadFlashes(data.flash) if Travis.app?.router && data.flash
      delete data.flash
      success.call(this, data)

    options.error = (data) =>
      Travis.app.router.flashController.pushObject(data.flash) if data.flash

    $.ajax($.extend(options, Travis.ajax.DEFAULT_OPTIONS))<commit_msg>Add error callback to Travis.ajax, pass all args to callbacks<commit_after>jQuery.support.cors = true

@Travis.ajax = Em.Object.create
  DEFAULT_OPTIONS:
    accepts:
      json: 'application/vnd.travis-ci.2+json'

  get: (url, callback) ->
    @ajax(url, 'get', success: callback)

  post: (url, data, callback) ->
    @ajax(url, 'post', data: data, success: callback)

  ajax: (url, method, options) ->
    method = method.toUpperCase()
    endpoint = Travis.config.api_endpoint || ''
    options = options || {}

    if token = Travis.sessionStorage.getItem('travis.token')
      options.headers ||= {}
      options.headers['Authorization'] ||= "token #{token}"

    options.url = "#{endpoint}#{url}"
    options.type = method
    options.dataType = options.dataType || 'json'
    options.context = this

    if options.data && method != 'GET'
      options.data = JSON.stringify(options.data)

    if method != 'GET' && method != 'HEAD'
      options.contentType = options.contentType || 'application/json; charset=utf-8'

    success = options.success || (->)
    options.success = (data) =>
      Travis.app.router.flashController.loadFlashes(data.flash) if Travis.app?.router && data.flash
      delete data.flash
      success.apply(this, arguments)

    error = options.error || (->)
    options.error = (data) =>
      Travis.app.router.flashController.pushObject(data.flash) if data.flash
      delete data.flash
      error.apply(this, arguments)

    $.ajax($.extend(options, Travis.ajax.DEFAULT_OPTIONS))
{'fraction_non_alphanumeric': 0.15323417502594258, 'fraction_numerical': 0.0013836042891732965, 'mean_word_length': 3.265486725663717, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, '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': '4995477', 'n_tokens_mistral': 912, 'n_tokens_neox': 894, 'n_words': 184}