<commit_before>/***********************************************************

 The information in this document is proprietary
 to VeriSign and the VeriSign Product Development.
 It may not be used, reproduced or disclosed without
 the written approval of the General Manager of
 VeriSign Product Development.

 PRIVILEGED AND CONFIDENTIAL
 VERISIGN PROPRIETARY INFORMATION
 REGISTRY SENSITIVE INFORMATION

 Copyright (c) 2013 VeriSign, Inc.  All rights reserved.

***********************************************************/

(function() {
    "use strict";

    var request = null;
    var wrapCallback = null;

    var wrapError = function(err) {
        return { "error" : err };
    };

    var SisApiEndpoint = function(apiBase, endpointOptions, client) {

        var idField = endpointOptions.idField;

        var getHeaders = function(addContentType) {
            var headers = {"Accept" : "application/json"};
            if (addContentType) {
                headers['Content-Type'] = 'application/json';
            }
            if (client.authToken) {
                headers['x-auth-token'] = client.authToken;
            }
            return headers;
        };

        this.listAll = function(query, callback) {
            var opts = { 'url' : apiBase,
                         'method' : 'GET',
                         'json' : true,
                         'headers' : getHeaders(false)
                       };
            if (typeof query == 'function') {
                callback = query;
                query = null;
            }
            query = query || {};
            var result = [];
            query.limit = 200;
            query.offset = 0;

            var self = this;

            var listCallback = function(err, res) {
                if (err) {
                    return callback(err, null);
                }
                // append
                result = result.concat(res.results);
                if (res.results.length < query.limit) {
                    return callback(null, result);
                }
                query.offset = result.length;
                self.list(query, listCallback);
            };

            this.list(query, listCallback);
        };

        this.list = function(query, callback) {
            var opts = { 'url' : apiBase,
                         'method' : 'GET',
                         'json' : true,
                         'headers' : getHeaders(false)
                       };
            if (typeof query == 'function') {
                callback = query;
            } else {
                opts.qs = query;
            }
            request(opts, wrapCallback(callback));
        };

        this.get = function(id, callback) {
            if (!id || typeof id === 'function') {
                if (typeof id === 'function') {
                    return id(wrapError("id is invalid"), null);
                } else {
                    if (callback) {
                        return callback(wrapError("id is invalid"), null);
                    } else {
                        throw "id is invalid";
                    }
                }
            }
            var endpoint = apiBase + '/' + id;
            var opts = { 'url' : endpoint,
                         'method' : 'GET',
                         'json' : true,
                         'headers' : getHeaders(false)
                       };
            request(opts, wrapCallback(callback));
        };

        this.create = function(obj, callback) {
            if (!obj) {
                return callback(wrapError("Object is invalid"), null);
            }
            var opts = { 'url' : apiBase,
                         'method' : 'POST',
                         'headers' : getHeaders(true),
                         'json' : obj };
            request(opts, wrapCallback(callback));
        };

        this.update = function(obj, callback) {
            if (!obj) {
                return callback(wrapError("Object is invalid"), null);
            }
            if (!(idField in obj)) {
                return callback(wrapError("Object is missing required field " + idField), null);
            }
            var endpoint = apiBase + '/' + obj[idField];
            var opts = { 'url' : endpoint,
                         'method' : 'PUT',
                         'headers' : getHeaders(true),
                         'json' : obj
                       };
            request(opts, wrapCallback(callback));
        };

        this.delete = function(obj, callback) {
            if (!obj) {
                return callback(wrapError("id is invalid"), null);
            }
            var id = obj;
            if (typeof obj === 'object') {
                if (!(idField in obj)) {
                    return callback(wrapError('Object is missing required field ' + idField), null);
                } else {
                    id = obj[idField];
                }
            }
            var endpoint = apiBase + '/' + id;
            var opts = { 'url' : endpoint,
                         'method' : 'DELETE',
                         'json' : true,
                         'headers' : getHeaders(false)
                       };
            request(opts, wrapCallback(callback));
        };

    };

    var SisClient = function(options) {

        // at least the base url is required
        if (!options || !options.url) {
            throw new TypeError("Options are invalid.  Base URL is required.");
        }
        var url = options.url;
        if (url.indexOf('http:') !== 0 &&
            url.indexOf('https:' !== 0)) {
            throw new TypeError("Base URL has an invalid protocol ");
        }

        var baseUrl = options.url;
        var entityEndpoints = { };

        var getApiEndpoint = function(endpoint) {
            if (baseUrl[baseUrl.length - 1] == '/') {
                endpoint = endpoint.substring(1);
            }
            return baseUrl + endpoint;
        };

        this.hooks = new SisApiEndpoint(getApiEndpoint('/api/v1/hooks'), { 'idField' : 'name' }, this);
        this.schemas = new SisApiEndpoint(getApiEndpoint('/api/v1/schemas'), { 'idField' : 'name'}, this);
        this.hiera = new SisApiEndpoint(getApiEndpoint('/api/v1/hiera'), { 'idField' : 'name'}, this);
        this.users = new SisApiEndpoint(getApiEndpoint('/api/v1/users'), { 'idField' : 'name'}, this);
<commit_msg>Fix https detection that should have been picked up in jshint.  Sad.<commit_after>/***********************************************************

 The information in this document is proprietary
 to VeriSign and the VeriSign Product Development.
 It may not be used, reproduced or disclosed without
 the written approval of the General Manager of
 VeriSign Product Development.

 PRIVILEGED AND CONFIDENTIAL
 VERISIGN PROPRIETARY INFORMATION
 REGISTRY SENSITIVE INFORMATION

 Copyright (c) 2013 VeriSign, Inc.  All rights reserved.

***********************************************************/

(function() {
    "use strict";

    var request = null;
    var wrapCallback = null;

    var wrapError = function(err) {
        return { "error" : err };
    };

    var SisApiEndpoint = function(apiBase, endpointOptions, client) {

        var idField = endpointOptions.idField;

        var getHeaders = function(addContentType) {
            var headers = {"Accept" : "application/json"};
            if (addContentType) {
                headers['Content-Type'] = 'application/json';
            }
            if (client.authToken) {
                headers['x-auth-token'] = client.authToken;
            }
            return headers;
        };

        this.listAll = function(query, callback) {
            var opts = { 'url' : apiBase,
                         'method' : 'GET',
                         'json' : true,
                         'headers' : getHeaders(false)
                       };
            if (typeof query == 'function') {
                callback = query;
                query = null;
            }
            query = query || {};
            var result = [];
            query.limit = 200;
            query.offset = 0;

            var self = this;

            var listCallback = function(err, res) {
                if (err) {
                    return callback(err, null);
                }
                // append
                result = result.concat(res.results);
                if (res.results.length < query.limit) {
                    return callback(null, result);
                }
                query.offset = result.length;
                self.list(query, listCallback);
            };

            this.list(query, listCallback);
        };

        this.list = function(query, callback) {
            var opts = { 'url' : apiBase,
                         'method' : 'GET',
                         'json' : true,
                         'headers' : getHeaders(false)
                       };
            if (typeof query == 'function') {
                callback = query;
            } else {
                opts.qs = query;
            }
            request(opts, wrapCallback(callback));
        };

        this.get = function(id, callback) {
            if (!id || typeof id === 'function') {
                if (typeof id === 'function') {
                    return id(wrapError("id is invalid"), null);
                } else {
                    if (callback) {
                        return callback(wrapError("id is invalid"), null);
                    } else {
                        throw "id is invalid";
                    }
                }
            }
            var endpoint = apiBase + '/' + id;
            var opts = { 'url' : endpoint,
                         'method' : 'GET',
                         'json' : true,
                         'headers' : getHeaders(false)
                       };
            request(opts, wrapCallback(callback));
        };

        this.create = function(obj, callback) {
            if (!obj) {
                return callback(wrapError("Object is invalid"), null);
            }
            var opts = { 'url' : apiBase,
                         'method' : 'POST',
                         'headers' : getHeaders(true),
                         'json' : obj };
            request(opts, wrapCallback(callback));
        };

        this.update = function(obj, callback) {
            if (!obj) {
                return callback(wrapError("Object is invalid"), null);
            }
            if (!(idField in obj)) {
                return callback(wrapError("Object is missing required field " + idField), null);
            }
            var endpoint = apiBase + '/' + obj[idField];
            var opts = { 'url' : endpoint,
                         'method' : 'PUT',
                         'headers' : getHeaders(true),
                         'json' : obj
                       };
            request(opts, wrapCallback(callback));
        };

        this.delete = function(obj, callback) {
            if (!obj) {
                return callback(wrapError("id is invalid"), null);
            }
            var id = obj;
            if (typeof obj === 'object') {
                if (!(idField in obj)) {
                    return callback(wrapError('Object is missing required field ' + idField), null);
                } else {
                    id = obj[idField];
                }
            }
            var endpoint = apiBase + '/' + id;
            var opts = { 'url' : endpoint,
                         'method' : 'DELETE',
                         'json' : true,
                         'headers' : getHeaders(false)
                       };
            request(opts, wrapCallback(callback));
        };

    };

    var SisClient = function(options) {

        // at least the base url is required
        if (!options || !options.url) {
            throw new TypeError("Options are invalid.  Base URL is required.");
        }
        var url = options.url;
        if (url.indexOf('http:') !== 0 &&
            url.indexOf('https:') !== 0) {
            throw new TypeError("Base URL has an invalid protocol ");
        }

        var baseUrl = options.url;
        var entityEndpoints = { };

        var getApiEndpoint = function(endpoint) {
            if (baseUrl[baseUrl.length - 1] == '/') {
                endpoint = endpoint.substring(1);
            }
            return baseUrl + endpoint;
        };

        this.hooks = new SisApiEndpoint(getApiEndpoint('/api/v1/hooks'), { 'idField' : 'name' }, this);
        this.schemas = new SisApiEndpoint(getApiEndpoint('/api/v1/schemas'), { 'idField' : 'name'}, this);
        this.hiera = new SisApiEndpoint(getApiEndpoint('/api/v1/hiera'), { 'idField' : 'name'}, this);
        this.users = new SisApiEndpoint(getApiEndpoint('/api/v1/users'), { 'idField' : 'name'}, this);

{'fraction_non_alphanumeric': 0.13160132993118379, 'fraction_numerical': 0.0024742905744993427, 'mean_word_length': 1.322499551086371, 'pattern_counts': {'":': 0, '<': 5, '<?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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3458951', 'n_tokens_mistral': 3271, 'n_tokens_neox': 3064, 'n_words': 819}