UNPKG

rtm-api

Version:

Remember the Milk API Interface

209 lines (164 loc) 9.49 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>user/lists.js - Documentation</title> <script src="scripts/prettify/prettify.js"></script> <script src="scripts/prettify/lang-css.js"></script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc.css"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> <input type="checkbox" id="nav-trigger" class="nav-trigger" /> <label for="nav-trigger" class="navicon-button x"> <div class="navicon"></div> </label> <label for="nav-trigger" class="overlay"></label> <nav> <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="RTMClient.html">RTMClient</a><ul class='methods'><li data-type='method'><a href="RTMClient.html#get">get</a></li><li data-type='method'><a href="RTMClient.html#~auth/getAuthToken">auth/getAuthToken</a></li><li data-type='method'><a href="RTMClient.html#~auth/getAuthUrl">auth/getAuthUrl</a></li><li data-type='method'><a href="RTMClient.html#~auth/verifyAuthToken">auth/verifyAuthToken</a></li><li data-type='method'><a href="RTMClient.html#~user/create">user/create</a></li><li data-type='method'><a href="RTMClient.html#~user/export">user/export</a></li><li data-type='method'><a href="RTMClient.html#~user/exportToString">user/exportToString</a></li><li data-type='method'><a href="RTMClient.html#~user/import">user/import</a></li><li data-type='method'><a href="RTMClient.html#~user/importFromString">user/importFromString</a></li></ul></li><li><a href="RTMError.html">RTMError</a><ul class='methods'><li data-type='method'><a href="RTMError.html#.networkError">networkError</a></li><li data-type='method'><a href="RTMError.html#.rateLimitError">rateLimitError</a></li><li data-type='method'><a href="RTMError.html#.referenceError">referenceError</a></li><li data-type='method'><a href="RTMError.html#.responseError">responseError</a></li><li data-type='method'><a href="RTMError.html#.serverError">serverError</a></li><li data-type='method'><a href="RTMError.html#toString">toString</a></li></ul></li><li><a href="RTMList.html">RTMList</a></li><li><a href="RTMResponse.html">RTMResponse</a><ul class='methods'><li data-type='method'><a href="RTMResponse.html#has">has</a></li><li data-type='method'><a href="RTMResponse.html#toString">toString</a></li></ul></li><li><a href="RTMSuccess.html">RTMSuccess</a><ul class='methods'><li data-type='method'><a href="RTMSuccess.html#toString">toString</a></li></ul></li><li><a href="RTMTask.html">RTMTask</a></li><li><a href="RTMUser.html">RTMUser</a><ul class='methods'><li data-type='method'><a href="RTMUser.html#clearTaskIndexCache">clearTaskIndexCache</a></li><li data-type='method'><a href="RTMUser.html#get">get</a></li><li data-type='method'><a href="RTMUser.html#verifyAuthToken">verifyAuthToken</a></li><li data-type='method'><a href="RTMUser.html#~lists/add">lists/add</a></li><li data-type='method'><a href="RTMUser.html#~lists/archive">lists/archive</a></li><li data-type='method'><a href="RTMUser.html#~lists/get">lists/get</a></li><li data-type='method'><a href="RTMUser.html#~lists/remove">lists/remove</a></li><li data-type='method'><a href="RTMUser.html#~lists/rename">lists/rename</a></li><li data-type='method'><a href="RTMUser.html#~tasks/add">tasks/add</a></li><li data-type='method'><a href="RTMUser.html#~tasks/addTags">tasks/addTags</a></li><li data-type='method'><a href="RTMUser.html#~tasks/complete">tasks/complete</a></li><li data-type='method'><a href="RTMUser.html#~tasks/decreasePriority">tasks/decreasePriority</a></li><li data-type='method'><a href="RTMUser.html#~tasks/get">tasks/get</a></li><li data-type='method'><a href="RTMUser.html#~tasks/getTask">tasks/getTask</a></li><li data-type='method'><a href="RTMUser.html#~tasks/increasePriority">tasks/increasePriority</a></li><li data-type='method'><a href="RTMUser.html#~tasks/move">tasks/move</a></li><li data-type='method'><a href="RTMUser.html#~tasks/postpone">tasks/postpone</a></li><li data-type='method'><a href="RTMUser.html#~tasks/priority">tasks/priority</a></li><li data-type='method'><a href="RTMUser.html#~tasks/remove">tasks/remove</a></li><li data-type='method'><a href="RTMUser.html#~tasks/removeTags">tasks/removeTags</a></li><li data-type='method'><a href="RTMUser.html#~tasks/setDueDate">tasks/setDueDate</a></li><li data-type='method'><a href="RTMUser.html#~tasks/setName">tasks/setName</a></li><li data-type='method'><a href="RTMUser.html#~tasks/setURL">tasks/setURL</a></li><li data-type='method'><a href="RTMUser.html#~tasks/uncomplete">tasks/uncomplete</a></li></ul></li></ul> </nav> <div id="main"> <h1 class="page-title">user/lists.js</h1> <section> <article> <pre class="prettyprint source linenums"><code>'use strict'; const errors = require('../response/error.js'); const _lists = require('../list/helper.js'); /** * This module returns the RTM list-related functions for the RTMUser * @param {RTMUser} user RTM User instance * @returns {{get: function, update: function, add: function, remove: function, rename: function, archive: function}} * @private */ module.exports = function(user) { let rtn = {}; /** * Get the list of RTM Lists for this User from the API Server * @param {function} callback Callback function(err, lists) * @param {RTMError} callback.err RTM API Error Response, if encountered * @param {RTMList[]} callback.lists List of User's RTM Lists * @function RTMUser~lists/get */ rtn.get = function(callback) { _lists.get(user, callback); }; /** * Add a new RTM List for this User * @param {string} name Name of the new RTM List * @param {string} [filter] Smart List Filter * @param {function} callback Callback function(err, lists) * @param {RTMError} callback.err RTM API Error Response, if encountered * @function RTMUser~lists/add */ rtn.add = function(name, filter, callback) { if ( callback === undefined &amp;&amp; typeof filter === 'function' ) { callback = filter; filter = undefined; } _lists.add(name, filter, user, callback); }; /** * Remove the specified RTM List for this User * @param {string} name RTM List Name * @param {function} callback Callback function(err) * @param {RTMError} callback.err RTM API Error Response, if encountered * @function RTMUser~lists/remove */ rtn.remove = function(name, callback) { // Get the User's Lists _lists.get(user, function(err, lists) { if ( err ) { return callback(err); } // Find the matching list IDs let ids = []; for ( let i = 0; i &lt; lists.length; i++ ) { if ( lists[i].name.toLowerCase() === name.toLowerCase() ) { ids.push(lists[i].id); } } // Remove the matching List if ( ids.length === 1 ) { return _lists.remove(ids[0], user, callback); } else { return callback(errors.referenceError()); } }); }; /** * Rename the specified RTM List for this User * @param {string} oldName Old RTM List Name * @param {string} newName New RTM List name * @param {function} callback Callback function(err) * @param {RTMError} callback.err RTM API Error Response, if encountered * @function RTMUser~lists/rename */ rtn.rename = function(oldName, newName, callback) { // Get the User's Lists _lists.get(user, function(err, lists) { if ( err ) { return callback(err); } // Find the matching list IDs let ids = []; for ( let i = 0; i &lt; lists.length; i++ ) { if ( lists[i].name.toLowerCase() === oldName.toLowerCase() ) { ids.push(lists[i].id); } } // Rename the matching List if ( ids.length === 1 ) { return _lists.rename(ids[0], newName, user, callback); } else { return callback(errors.referenceError()); } }); }; /** * Archive the specified RTM List for this User * @param {string} name RTM List Name * @param {function} callback Callback function(err) * @param {RTMError} callback.err RTM API Error Response, if encountered * @function RTMUser~lists/archive */ rtn.archive = function(name, callback) { // Get the User's Lists _lists.get(user, function(err, lists) { if ( err ) { return callback(err); } // Find the matching list IDs let ids = []; for ( let i = 0; i &lt; lists.length; i++ ) { if ( lists[i].name.toLowerCase() === name.toLowerCase() ) { ids.push(lists[i].id); } } // Remove the matching List if ( ids.length === 1 ) { return _lists.archive(ids[0], user, callback); } else { return callback(errors.referenceError()); } }); }; return rtn; };</code></pre> </article> </section> </div> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Wed Jan 09 2019 17:57:03 GMT-0500 (EST) using the <a href="https://github.com/dwaring87/docdash">@dwaring87/docdash</a> theme. </footer> <script>prettyPrint();</script> <script src="scripts/linenumber.js"></script> </body> </html>