<commit_before>jQuery.support.cors = true

Travis.ajax = Em.Object.create
  publicEndpoints: [/\/repos\/?.*/, /\/builds\/?.*/, /\/jobs\/?.*/]

  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)

  needsAuth: (method, url) ->
    return false if method != 'GET'

    result = @publicEndpoints.find (pattern) ->
      url.match(pattern)

    !result

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

    token = Travis.sessionStorage.getItem('travis.token')
    if token && Travis.ajax.needsAuth(method, url)
      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 || (->)<commit_msg>POST requests should always require auth<commit_after>jQuery.support.cors = true

Travis.ajax = Em.Object.create
  publicEndpoints: [/\/repos\/?.*/, /\/builds\/?.*/, /\/jobs\/?.*/]

  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)

  needsAuth: (method, url) ->
    return true if method != 'GET'

    result = @publicEndpoints.find (pattern) ->
      url.match(pattern)

    !result

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

    token = Travis.sessionStorage.getItem('travis.token')
    if token && Travis.ajax.needsAuth(method, url)
      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 || (->)
{'fraction_non_alphanumeric': 0.1723076923076923, 'fraction_numerical': 0.0015384615384615385, 'mean_word_length': 3.0388198757763973, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '7375014', 'n_tokens_mistral': 848, 'n_tokens_neox': 820, 'n_words': 181}