rtm-api
Version:
Remember the Milk API Interface
171 lines (140 loc) • 8.57 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>client/user.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">client/user.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>'use strict';
const RTMClient = require('./index.js');
const RTMUser = require('../user/index.js');
/**
* This module returns the user-related functions for RTMClient
* @param {RTMClient} client RTMClient instance
* @returns {{create: function, export: function, exportToString: function, import: function, importFromString: function}}
*/
module.exports = function(client) {
let rtn = {};
/**
* Create a new `RTMUser` manually.
*
* This will also set the User's RTM API Client to this `RTMClient`.
* @param {number} id The RTM User's ID
* @param {string} username The RTM User's username
* @param {string} fullname The RTM User's full name
* @param {string} authToken The RTM User's Auth Token
* @returns {RTMUser}
* @function RTMClient~user/create
*/
rtn.create = function(id, username, fullname, authToken) {
let user = new RTMUser(id, username, fullname, authToken);
user.client = client;
return user;
};
/**
* Get the User's required information:
* - id
* - username
* - fullname
* - authToken
* - client (if set or use this `RTMClient`)
* @param {RTMUser} user The RTMUser to export
* @returns {object}
* @function RTMClient~user/export
*/
rtn.export = function(user) {
let rtn = {
id: user.id,
username: user.username,
fullname: user.fullname,
authToken: user.authToken,
timeline: user._timeline
};
if ( user.client ) {
rtn.client = {
apiKey: user.client.key,
apiSecret: user.client.secret,
perms: user.client.perms
}
}
else {
rtn.client = {
apiKey: client.key,
apiSecret: client.key,
perms: client.perms
}
}
return rtn;
};
/**
* Get the User's required information as a JSON-string
* @param {RTMUser} user The RTMUser to export
* @returns {string}
* @function RTMClient~user/exportToString
*/
rtn.exportToString = function(user) {
return JSON.stringify(rtn.export(user));
};
/**
* Create a new `RTMUser` from an exported User's properties
* @param {Object} properties The RTM User's required properties
* @returns {RTMUser}
* @function RTMClient~user/import
*/
rtn.import = function(properties) {
if ( properties.id && properties.username && properties.fullname && properties.authToken ) {
let user = new RTMUser(properties.id, properties.username, properties.fullname, properties.authToken);
if ( properties.timeline ) {
user.timeline = properties.timeline;
}
if ( properties.client ) {
user.client = new RTMClient(properties.client.apiKey, properties.client.apiSecret, properties.client.perms);
}
return user;
}
else {
throw "Missing User Properties";
}
};
/**
* Create a new `RTMUser` from an exported User's properties' JSON-string
* @param {string} string JSON-string of RTM User's required properties
* @returns {RTMUser}
* @function RTMClient~user/importFromString
*/
rtn.importFromString = function(string) {
return rtn.import(JSON.parse(string));
};
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>