Skip to content

Instantly share code, notes, and snippets.

@lmrodriguezr
Created January 28, 2009 00:41
Show Gist options
  • Save lmrodriguezr/53738 to your computer and use it in GitHub Desktop.
Save lmrodriguezr/53738 to your computer and use it in GitHub Desktop.
CmdUtils.CreateCommand({
name: "todoist-add-key",
preview: function(pblock,apiKey){
if(apiKey.text)
pblock.innerHTML="Press &lt;enter&gt; to save your API Key <b>"+apiKey.text+"</b>.<br/><br/>Use todoist-signout to delete your API Key reference.";
else
pblock.innerHTML="Please provide your Todoist API Key, use todoist-signout to delete your API Key reference.";
},
icon: "http://todoist.com/favicon.ico",
takes: {"key": noun_arb_text},
execute: function ( apiKey ) {
if (!Application.prefs.has("todoist_api_key")) {
Application.prefs.setValue("todoist_api_key", apiKey);
} else {
var new_key = Application.prefs.get("todoist_api_key");
new_key.value = apiKey;
return new_key.value;
}
}
});
CmdUtils.CreateCommand({
name: "todoist",
preview: function ( pblock, whichTasks ){
if(!whichTasks) whichTasks='Completed';
if(!Application.prefs.has("todoist_api_key")){
pblock.innerHTML="Please provide your Todoist Token API using the todoist-add-key verb";
//var todoistToken = prompt("Please enter your todoist API key","");
}else{
var apiKey=Application.prefs.get("todoist_api_key");
jQuery.getJSON("http://todoist.com/API/getProjects?token="+apiKey,
function(jsonReq){
jsonReq.each(
function(jsonElement){
pblock.innerHTML+=jsonElement+"<br/>";
}
);
}
);
}
},
icon: "http://todoist.com/favicon.ico",
takes: {"Completed | Uncompleted": noun_arb_text},
execute: function ( whichTasks ) {
Utils.openUrlInBrowser( "http://todoist.com/" );
}
});
CmdUtils.CreateCommand({
name: "todoist-signout",
preview: "Sign out from Todoist (only for ubiquity)",
icon: "http://todoist.com/favicon.ico",
execute: function () {
if (!Application.prefs.has("todoist_api_key")) {
Application.prefs.setValue("todoist_api_key", "");
} else {
var new_key = Application.prefs.get("todoist_api_key");
new_key.value = "";
return new_key.value;
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment