<commit_before>import $ from 'jquery';

import {
  assign,
} from './utils';

var dataInterface;
(function(){
  var $ajax = (o)=> {
    return $.ajax(assign({}, {dataType: 'json', method: 'GET'}, o));
  };
  const assetMapping = {
    'a': 'assets',
    'c': 'collections',
    'p': 'permissions',
  };

  var rootUrl = (function(){
    try {
      return document.head.querySelector('meta[name=kpi-root-url]').content.replace(/\/$/, '');
    } catch (e) {
      console.error('no kpi-root-url meta tag set. defaulting to ""');
      return '';
    }
  })();
  this.rootUrl = rootUrl;

  assign(this, {
    selfProfile: ()=> $ajax({ url: `${rootUrl}/me/` }),
    serverEnvironment: ()=> $ajax({ url: `${rootUrl}/environment/` }),
    queryUserExistence: (username)=> {
      var d = new $.Deferred();
      $ajax({ url: `${rootUrl}/users/${username}/` })
        .done(()=>{ d.resolve(username, true); })
        .fail(()=>{ d.reject(username, false); });
      return d.promise();
    },
    logout: ()=> {
      var d = new $.Deferred();
      $ajax({ url: `${rootUrl}/api-auth/logout/` }).done(d.resolve).fail(function (/*resp, etype, emessage*/) {
        // logout request wasn't successful, but may have logged the user out
        // querying '/me/' can confirm if we have logged out.
        dataInterface.selfProfile().done(function(data){
          if (data.message === 'user is not logged in') {
            d.resolve(data);
          } else {
            d.fail(data);
          }
        }).fail(d.fail);
      });
      return d.promise();
    },
    patchProfile (data) {
      return $ajax({
        url: `${rootUrl}/me/`,
        method: 'PATCH',
        data: data
      });
    },
    listTemplates () {
      return $ajax({
        url: `${rootUrl}/assets/?q=asset_type:template`
      });
    },
    listCollections () {
      return $.getJSON(`${rootUrl}/collections/?all_public=true`);
    },
    createAssetSnapshot (data) {
      return $ajax({
        url: `${rootUrl}/asset_snapshots/`,
        method: 'POST',
        data: data
      });
    },

    /*
     * external services
     */

    getHooks(uid) {
      return $ajax({
        url: `${rootUrl}/assets/${uid}/hooks/`,
        method: 'GET'
      });
    },
    getHook(uid, hookUid) {
      return $ajax({
        url: `${rootUrl}/assets/${uid}/hooks/${hookUid}`,
        method: 'GET'
      });
    },
    addExternalService(uid, data) {
      return $ajax({
        url: `${rootUrl}/assets/${uid}/hooks/`,
        method: 'POST',
        data: JSON.stringify(data),
        dataType: 'json',
        contentType: 'application/json'
      });
    },
    updateExternalService(uid, hookUid, data) {
      return $ajax({
        url: `${rootUrl}/assets/${uid}/hooks/${hookUid}`,
        method: 'PATCH',
        data: JSON.stringify(data),
        dataType: 'json',
        contentType: 'application/json'
      });
    },
    deleteExternalService(uid, hookUid) {
      return $ajax({
        url: `${rootUrl}/assets/${uid}/hooks/${hookUid}`,
        method: 'DELETE'
      });
    },
    getHookLogs(uid, hookUid) {
      return $ajax({
        url: `/assets/${uid}/hooks/${hookUid}/logs/`,
        method: 'GET'<commit_msg>add / to api calls<commit_after>import $ from 'jquery';

import {
  assign,
} from './utils';

var dataInterface;
(function(){
  var $ajax = (o)=> {
    return $.ajax(assign({}, {dataType: 'json', method: 'GET'}, o));
  };
  const assetMapping = {
    'a': 'assets',
    'c': 'collections',
    'p': 'permissions',
  };

  var rootUrl = (function(){
    try {
      return document.head.querySelector('meta[name=kpi-root-url]').content.replace(/\/$/, '');
    } catch (e) {
      console.error('no kpi-root-url meta tag set. defaulting to ""');
      return '';
    }
  })();
  this.rootUrl = rootUrl;

  assign(this, {
    selfProfile: ()=> $ajax({ url: `${rootUrl}/me/` }),
    serverEnvironment: ()=> $ajax({ url: `${rootUrl}/environment/` }),
    queryUserExistence: (username)=> {
      var d = new $.Deferred();
      $ajax({ url: `${rootUrl}/users/${username}/` })
        .done(()=>{ d.resolve(username, true); })
        .fail(()=>{ d.reject(username, false); });
      return d.promise();
    },
    logout: ()=> {
      var d = new $.Deferred();
      $ajax({ url: `${rootUrl}/api-auth/logout/` }).done(d.resolve).fail(function (/*resp, etype, emessage*/) {
        // logout request wasn't successful, but may have logged the user out
        // querying '/me/' can confirm if we have logged out.
        dataInterface.selfProfile().done(function(data){
          if (data.message === 'user is not logged in') {
            d.resolve(data);
          } else {
            d.fail(data);
          }
        }).fail(d.fail);
      });
      return d.promise();
    },
    patchProfile (data) {
      return $ajax({
        url: `${rootUrl}/me/`,
        method: 'PATCH',
        data: data
      });
    },
    listTemplates () {
      return $ajax({
        url: `${rootUrl}/assets/?q=asset_type:template`
      });
    },
    listCollections () {
      return $.getJSON(`${rootUrl}/collections/?all_public=true`);
    },
    createAssetSnapshot (data) {
      return $ajax({
        url: `${rootUrl}/asset_snapshots/`,
        method: 'POST',
        data: data
      });
    },

    /*
     * external services
     */

    getHooks(uid) {
      return $ajax({
        url: `${rootUrl}/assets/${uid}/hooks/`,
        method: 'GET'
      });
    },
    getHook(uid, hookUid) {
      return $ajax({
        url: `${rootUrl}/assets/${uid}/hooks/${hookUid}/`,
        method: 'GET'
      });
    },
    addExternalService(uid, data) {
      return $ajax({
        url: `${rootUrl}/assets/${uid}/hooks/`,
        method: 'POST',
        data: JSON.stringify(data),
        dataType: 'json',
        contentType: 'application/json'
      });
    },
    updateExternalService(uid, hookUid, data) {
      return $ajax({
        url: `${rootUrl}/assets/${uid}/hooks/${hookUid}/`,
        method: 'PATCH',
        data: JSON.stringify(data),
        dataType: 'json',
        contentType: 'application/json'
      });
    },
    deleteExternalService(uid, hookUid) {
      return $ajax({
        url: `${rootUrl}/assets/${uid}/hooks/${hookUid}/`,
        method: 'DELETE'
      });
    },
    getHookLogs(uid, hookUid) {
      return $ajax({
        url: `/assets/${uid}/hooks/${hookUid}/logs/`,
        method: 'GET'
{'fraction_non_alphanumeric': 0.19776119402985073, 'fraction_numerical': 0.0, 'mean_word_length': 2.1549779303580188, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '7430118', 'n_tokens_mistral': 2051, 'n_tokens_neox': 2108, 'n_words': 418}