<commit_before>//create the SUGAR namespace if one does not exist already
var SUGAR = SUGAR || {};

//create an Api namespace
SUGAR.Api = (function () {
    var instance;
    var methodsToRequest = {
        "get":"GET",
        "update":"PUT",
        "create":"POST",
        "delete":"DELETE"
    };

    function init(args) {
        instance = new SugarApi(args);
        return instance;
    }

    /*
     * This is a constructor for API class
     * @params: pass optional arguments
     */
    function SugarApi(args) {
        var token="";
        var isAuth= false;
        // vars to store uesr callbacks for login and logout
        var _loginCallbacks = {};
        var _logoutCallbacks = {};

        /**
         * handles login success, calls user callbacks after it sets internal token and isAuth
         *
         * @param  object processed json response from successful login
         */
        function handleLoginSuccess(successObj) {
            isAuth = true;
            if (successObj.token) {
                token = successObj.token;
            }
            if (_loginCallbacks.success) {
                _loginCallbacks.success(successObj);
            }
        }

        /**
         * handles login error, calls user supplied callbacks to .logout passing the ajax request object
         *
         * @param  object
         */
        function handleLoginFailure(failObj){
            isAuth = false;
            if (_loginCallbacks.error) {
                _loginCallbacks.error(failObj);
            }
        }

        /**
         * handles logout success, calls user callbacks after it clears internal token and isAuth
         *
         * @param  object processed json response from successful logout in this case its null
         */
        function handleLogoutSuccess(successObj) {
            isAuth = false;
            token="";

            if (_logoutCallbacks.success) {
                _logoutCallbacks.success(successObj);
            }

        }

        /**
         * handles logout error, calls user supplied callbacks to .logout passing the ajax request object
         *
         * @param  object jquery ajax request object
         */
        function handleLogoutFailure(failObj){
            isAuth = true;
            //console.log("logout fail");

            if (_logoutCallbacks.error) {
                _logoutCallbacks.error(failObj);
            }
        }

        return {
            baseUrl:"/rest/v10/",

            /**
             * make ajax call via jquery ajax
             *
             * @param  string request method to make, crud actions map above eg POST, GET, create,
             * @param  string url
             * @param  object attributes will be stringified and set to data eg {first_name:"bob", last_name:"saget"}
             * @param  array  options for request that map directly to the jquery.ajax options
             * @param  object with with callbacks of the format {success: function(data){}, error: function(data){}} to be called
             * @return object jquery Request object
             */
            call:function (method, url, attributes, options, callbacks) {
                options = options || {};
                callbacks = callbacks || {};
                var type = methodsToRequest[method];

                // by default use json headers
                var params = {type:type, dataType:'json'};

                // if we dont have a url from options take arg url
                if (!options.url) {
                    params.url = url;
                }
                //add callbacks
                if (callbacks.success) {
                    params.success = callbacks.success;
                }

                if (callbacks.error) {
                    params.error = callbacks.error;
                }

                // set data for create and update
                if (attributes && (method == 'create' || method == 'update')) {
                    params.contentType = 'application/json';
                    params.data = JSON.stringify(attributes);
                }

                // Don't process data on a non-GET request.
                if (params.type !== 'GET') {
                    params.processData = false;
                }
<commit_msg>adding debug to api<commit_after>//create the SUGAR namespace if one does not exist already
var SUGAR = SUGAR || {};

//create an Api namespace
SUGAR.Api = (function () {
    var instance;
    var methodsToRequest = {
        "get":"GET",
        "update":"PUT",
        "create":"POST",
        "delete":"DELETE"
    };

    function init(args) {
        instance = new SugarApi(args);
        return instance;
    }

    /*
     * This is a constructor for API class
     * @params: pass optional arguments
     */
    function SugarApi(args) {
        var token="";
        var isAuth= false;
        // vars to store uesr callbacks for login and logout
        var _loginCallbacks = {};
        var _logoutCallbacks = {};

        /**
         * handles login success, calls user callbacks after it sets internal token and isAuth
         *
         * @param  object processed json response from successful login
         */
        function handleLoginSuccess(successObj) {
            isAuth = true;
            if (successObj.token) {
                token = successObj.token;
            }
            if (_loginCallbacks.success) {
                _loginCallbacks.success(successObj);
            }
        }

        /**
         * handles login error, calls user supplied callbacks to .logout passing the ajax request object
         *
         * @param  object
         */
        function handleLoginFailure(failObj){
            isAuth = false;
            if (_loginCallbacks.error) {
                _loginCallbacks.error(failObj);
            }
        }

        /**
         * handles logout success, calls user callbacks after it clears internal token and isAuth
         *
         * @param  object processed json response from successful logout in this case its null
         */
        function handleLogoutSuccess(successObj) {
            isAuth = false;
            token="";

            if (_logoutCallbacks.success) {
                _logoutCallbacks.success(successObj);
            }

        }

        /**
         * handles logout error, calls user supplied callbacks to .logout passing the ajax request object
         *
         * @param  object jquery ajax request object
         */
        function handleLogoutFailure(failObj){
            isAuth = true;
            //console.log("logout fail");

            if (_logoutCallbacks.error) {
                _logoutCallbacks.error(failObj);
            }
        }

        return {
            baseUrl:"/rest/v10/",
            debug: false,

            /**
             * make ajax call via jquery ajax
             *
             * @param  string request method to make, crud actions map above eg POST, GET, create,
             * @param  string url
             * @param  object attributes will be stringified and set to data eg {first_name:"bob", last_name:"saget"}
             * @param  array  options for request that map directly to the jquery.ajax options
             * @param  object with with callbacks of the format {success: function(data){}, error: function(data){}} to be called
             * @return object jquery Request object
             */
            call:function (method, url, attributes, options, callbacks) {

                options = options || {};
                callbacks = callbacks || {};
                var type = methodsToRequest[method];

                if (this.debug) {
                    console.log("====== Ajax Request Begin ======");
                    console.log("Request URL: " + url);
                    console.log("Request Type: " + type);
                    console.log("Payload: ");
                    console.log(attributes);
                    console.log("====== Request End ======");
                }

                // by default use json headers
                var params = {type:type, dataType:'json'};

                // if we dont have a url from options take arg url
                if (!options.url) {
                    params.url = url;
                }
                //add callbacks
                if (callbacks.success) {
                    params.success = callbacks.success;
                }

                if (callbacks.error) {
                    params.error = callbacks.error;
                }

                // set data for create and update
                if (attributes && (method == 'create' || method == 'update')) {
                    params.contentType = 'application/json';
                    params.data = JSON.stringify(attributes);
                }

                // Don't process data on a non-GET request.
                if (params.type !== 'GET') {
                    params.processData = false;
                }

{'fraction_non_alphanumeric': 0.0908486594283182, 'fraction_numerical': 0.00044316419233325947, 'mean_word_length': 1.429878869448183, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 3, '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': '4858710', 'n_tokens_mistral': 2247, 'n_tokens_neox': 2115, 'n_words': 678}