-
Notifications
You must be signed in to change notification settings - Fork 5
Helper Functions
RTM API provides a number of helper functions attached to an RTMUser
instance that can be used to
get, add and modify a User's Lists and Tasks.
These helper functions require the use of an authenticated RTMUser
instance, which can be obtained
through the RTM API Authentication process (See the User Authentication Example).
For full documentation on the available helper functions, view the RTMUser Documentation.
List helper functions are available to get the User's current Lists, add a new List, rename a List and remove a List.
// Get all of the User's Lists
user.lists.get(function(err, lists) {
// Handle Error
if ( err ) {
return console.error(err);
}
// Parse each RTM List
for ( let i = 0; i < lists.length; i++ ) {
console.log("LIST: " + lists[i].name);
}
});
// Add a new 'Smart List', containing all tasks with a priority of 1
user.lists.add('Important', 'priority:1', function(err) {
// Handle Error
if ( err ) {
return console.error(err);
}
});
Task helper functions are available to get the User's current Tasks, add a new Task, complete a Task, move Tasks between Lists, remove a Task and edit the properties of a Task (such as its priority, tags, and due date).
Task helper functions that reference a specific task (such as tasks.addTags(index, tags, callback)
) do so using an index number, which is automatically generated by the RTM API when using the tasks.get()
helper function. The index number if available via the index
property of an RTMTask
instance.
// Get all of the User's Tasks user.tasks.get(function(err, tasks) {
// Handle Error
if ( err ) {
return console.error(err);
}
// Parse each Task
for ( let i = 0; i < tasks.length; i++ ) {
let task = tasks[i];
// Get Basic Task Info
let info = task.index + ": ";
info += task.name + " (";
info += "List: " + task.list.name + ", ";
info += "Pri: " + task.priority + ", ";
info += "Is Complete: " + task.isCompleted + ")";
console.log(info);
// Display All RTM Task Properties
console.log(JSON.stringify(task.props, null, 4));
}
});
// Get Tasks from the List 'jobs'
user.tasks.get("list:jobs", function(err, tasks) {
// Handle Error
if ( err ) {
return console.error(err);
}
// Parse each Task
for ( let i = 0; i < tasks.length; i++ ) {
let task = tasks[i];
// Get Basic Task Info
let info = task.index + ": ";
info += task.name + " (";
info += "List: " + task.list.name + ", ";
info += "Pri: " + task.priority + ", ";
info += "Is Complete: " + task.isCompleted + ")";
console.log(info);
// Display All RTM Task Properties
console.log(JSON.stringify(task.props, null, 4));
}
});
// Set the Priority of Task 14 to 2
user.tasks.priority(14, 2, function(err) {
// Handle Error
if ( err ) {
return console.error(err);
}
});