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AAW,EACX,OAAU,GAEd,EAAU,GAAW,CAAC,GAEjB,EAAE,SAAS,GACZ,MAAM,IAAI,UAAU,uBAIxB,OAFA,EAAQ,GAAK,EAEN,KAAK,YAAY,eAAgB,GAAS,QAAQ,EAC7D,EAEA,OAAO,QAAU","file":"/npm/tickspot-api@0.2.1/lib/tickspot.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/tickspot-api@0.2.1/lib/tickspot.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","var request = require('request'),\n    _ = require('underscore'),\n    Q = require('q'),\n    parseString = require('xml2js').parseString;\n\nfunction Tickspot(company, email, password) {\n    this.company = company;\n    this.email = email;\n    this.password = password;\n    this.host = 'https://' + company + '.tickspot.com';\n}\n\nTickspot.prototype._xmlValidator = function (xpath, currentValue, newValue) {\n    // Ensure that things which should be arrays stay as arrays\n    if (xpath == '/clients') {\n        return this._ensureArrayWrap(newValue.client);\n    } else if (xpath == '/entries') {\n        return this._ensureArrayWrap(newValue.entry);\n    } else if (xpath == '/users') {\n        return this._ensureArrayWrap(newValue.user);\n    } else if (['/projects', '/clients/client/projects'].indexOf(xpath) > -1) {\n        return this._ensureArrayWrap(newValue.project);\n    } else if (['/tasks', '/projects/project/tasks', '/clients/client/projects/project/tasks'].indexOf(xpath) > -1) {\n        return this._ensureArrayWrap(newValue.task);\n    }\n    return newValue;\n};\n\nTickspot.prototype._ensureArrayWrap = function (value) {\n    return _.isArray(value) ? value : [ value ];\n};\n\nTickspot.prototype._ensureDateString = function (date) {\n    return _.isDate(date) ? date.getFullYear() + '-' + this._pad(date.getMonth()+1, 2) + '-' + this._pad(date.getDate(), 2) : date;\n};\n\nTickspot.prototype._pad = function (number, size) {\n    var output = '' + number;\n    while (output.length < size) { output = '0' + output; }\n    return output;\n};\n\nTickspot.prototype.makeRequest = function (method, params) {\n    var scope = this;\n    var deferred = Q.defer();\n    request.post({\n        uri: this.host + '/api/' + method,\n        form: _.extend({\n            email: this.email,\n            password: this.password\n        }, params || {})\n    }, function (error, response, body) {\n        if (!error && [200, 201, 204, 304].indexOf(response.statusCode) > -1) {\n            if (body) {\n                parseString(body, {\n                    ignoreAttrs: true,\n                    explicitArray: false,\n                    validator: scope._xmlValidator.bind(scope)\n                }, deferred.makeNodeResolver());\n            } else {\n                deferred.resolve();\n            }\n        } else {\n            deferred.reject(error || body);\n        }\n    });\n    return deferred.promise;\n};\n\nTickspot.prototype.clients = function (options, callback) {\n    if (!_.isUndefined(options) && _.isFunction(options)) {\n        callback = options;\n        options = void 0;\n    }\n\n    return this.makeRequest('clients', options).then(function (data) {\n        return data.clients;\n    }).nodeify(callback);\n};\n\nTickspot.prototype.projects = function (options, callback) {\n    if (!_.isUndefined(options) && _.isFunction(options)) {\n        callback = options;\n        options = void 0;\n    }\n\n    return this.makeRequest('projects', options).then(function (data) {\n        return data.projects;\n    }).nodeify(callback);\n};\n\nTickspot.prototype.tasks = function (project_id, options, callback) {\n    if (!_.isUndefined(options) && _.isFunction(options)) {\n        callback = options;\n        options = void 0;\n    }\n    options = options || {};\n\n    if (!_.isNumber(project_id)) {\n        throw new TypeError('project_id is not numerical');\n    }\n    options.project_id = project_id;\n\n    return this.makeRequest('tasks', options).then(function (data) {\n        return data.tasks;\n    }).nodeify(callback);\n};\n\nTickspot.prototype.clientsProjectsTasks = function (callback) {\n    return this.makeRequest('clients_projects_tasks').then(function (data) {\n        return data.clients;\n    }).nodeify(callback);\n};\n\nTickspot.prototype.entries = function (start_date, end_date, options, callback) {\n    if (!_.isUndefined(options) && _.isFunction(options)) {\n        callback = options;\n        options = void 0;\n    }\n    if (!_.isUndefined(end_date)) {\n        if (_.isFunction(end_date)) {\n            callback = end_date;\n            end_date = void 0;\n        } else if (_.isUndefined(options) && !_.isString(end_date) && !_.isDate(end_date)) {\n            options = end_date;\n            end_date = void 0;\n        }\n    }\n    options = options || {};\n\n    if (!_.isString(start_date) && !_.isDate(start_date)) {\n        throw new TypeError('start_date is not a string or date');\n    }\n    if (!_.isUndefined(end_date) && !_.isString(end_date) && !_.isDate(end_date)) {\n        throw new TypeError('end_date is not a string or date');\n    }\n    options[end_date ? 'start_date' : 'updated_at'] = this._ensureDateString(start_date);\n    if (end_date) {\n        options.end_date = this._ensureDateString(end_date);\n    }\n\n    return this.makeRequest('entries', options).then(function (data) {\n        return data.entries;\n    }).nodeify(callback);\n};\n\nTickspot.prototype.recentTasks = function (callback) {\n    return this.makeRequest('recent_tasks').then(function (data) {\n        return data.tasks;\n    }).nodeify(callback);\n};\n\nTickspot.prototype.users = function (options, callback) {\n    if (!_.isUndefined(options) && _.isFunction(options)) {\n        callback = options;\n        options = void 0;\n    }\n\n    return this.makeRequest('users', options).then(function (data) {\n        return data.users;\n    }).nodeify(callback);\n};\n\nTickspot.prototype.createEntry = function (task_id, hours, date, options, callback) {\n    if (!_.isUndefined(options) && _.isFunction(options)) {\n        callback = options;\n        options = void 0;\n    }\n    options = options || {};\n\n    if (!_.isNumber(task_id)) {\n        throw new TypeError('task_id is not numerical');\n    }\n    if (!_.isNumber(hours)) {\n        throw new TypeError('hours is not numerical');\n    }\n    if (!_.isString(date) && !_.isDate(date)) {\n        throw new TypeError('date is not a string or date');\n    }\n    options.task_id = task_id;\n    options.hours = hours;\n    options.date = this._ensureDateString(date);\n\n    return this.makeRequest('create_entry', options).then(function (data) {\n        return data.entry;\n    }).nodeify(callback);\n};\n\nTickspot.prototype.updateEntry = function (id, options, callback) {\n    if (!_.isUndefined(options) && _.isFunction(options)) {\n        callback = options;\n        options = void 0;\n    }\n    options = options || {};\n\n    if (!_.isNumber(id)) {\n        throw new TypeError('id is not numerical');\n    }\n    options.id = id;\n    \n    return this.makeRequest('update_entry', options).nodeify(callback);\n};\n\nmodule.exports = Tickspot;"]}