Created
December 21, 2008 12:58
-
-
Save garyhodgson/38677 to your computer and use it in GitHub Desktop.
Ubiquity command for interacting with Tumblr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Tumblr = { | |
addUsername : function(username) { Application.prefs.setValue("tumblr_user_username", username);}, | |
getUsername : function() { return Application.prefs.get("tumblr_user_username").value;}, | |
addGroup : function(group) { Application.prefs.setValue("tumblr_group", group);}, | |
getGroup : function() { return Application.prefs.get("tumblr_group").value;}, | |
addPassword : function(password) { Application.prefs.setValue("tumblr_user_password", password); }, | |
getPassword : function() { return Application.prefs.get("tumblr_user_password").value; }, | |
everythingIsOK : function() { | |
return Application.prefs.has("tumblr_user_username") | |
&& Application.prefs.has("tumblr_user_password") | |
&& Application.prefs.has("tumblr_group"); | |
} | |
}; | |
CmdUtils.CreateCommand( { | |
name : "t-text", | |
homepage : "http://www.tumblr.com", | |
icon: "http://www.google.com/s2/favicons?domain=www.tumblr.com", | |
author : { name : "Chuck Masucci", homepage : "http://www.pokenewyork.com/"}, | |
description : "Create Tumblog entry. <span id='credit'>By <a href='http://www.pokenewyork.com/'>Chuck Masucci</a></span>", | |
help : "E.g. tumblr-text <i>hello world</i> title <i>my title</i>", | |
license : "MPL", | |
takes : {"tumbl" : noun_arb_text}, | |
modifiers : {"title" : noun_arb_text}, | |
preview : function(pblock, tumbl) { | |
pblock.innerHTML = "Will create a new Tumblr Text post<br>"; | |
}, | |
execute : function(tumbl, mods) { | |
var username = Tumblr.getUsername(); | |
var password = Tumblr.getPassword(); | |
var myGroup = Tumblr.getGroup(); | |
var myTumbl = tumbl.text; | |
var myTitle = mods.title.text || ""; | |
if (!Tumblr.everythingIsOK()) { | |
displayMessage("Your email and password hasn't been set. Please use the 'tumblr-setup' command to set your email and password."); | |
return; | |
} | |
jQuery.post("http://www.tumblr.com/api/write", | |
{ email : username, | |
password : password, | |
type : "regular", | |
generator : "Tumblr Ubiquity", | |
group : myGroup, | |
title : myTitle, | |
body : myTumbl | |
}, function(data) { displayMessage("Regular post completed!"); }); | |
} | |
}) | |
CmdUtils.CreateCommand( { | |
name : "t-link", | |
homepage : "http://www.tumblr.com", | |
author : { name : "Chuck Masucci", homepage : "http://www.pokenewyork.com/"}, | |
icon: "http://www.google.com/s2/favicons?domain=www.tumblr.com", | |
description : "Create Tumblog link entry. <span id='credit'>By <a href='http://www.pokenewyork.com/'>Chuck Masucci</a></span>", | |
help : "E.g. tumblr-link <i>http://www.google.com</i> name <i>Google</i> description <i>Search Here!</i>", | |
license : "MPL", | |
takes : {"tumbl" : noun_arb_text}, | |
modifiers : {"name" : noun_arb_text, "description" : noun_arb_text}, | |
preview : function(pblock, tumbl) { | |
pblock.innerHTML = "Will create a new Tumblr Link post<br>"; | |
}, | |
execute : function(tumbl, mods) { | |
var username = Tumblr.getUsername(); | |
var password = Tumblr.getPassword(); | |
var group = Tumblr.getGroup(); | |
var myTumbl = tumbl.text; | |
var myName = mods.name.text || ""; | |
var myDescription = mods.description.text || ""; | |
if (!Tumblr.everythingIsOK()) { | |
displayMessage("Your email and password hasn't been set. Please use the 'tumblr-setup' command to set your email and password."); | |
return; | |
} | |
jQuery.post("http://www.tumblr.com/api/write", | |
{ email : username, | |
password : password, | |
type : "link", | |
generator : "Tumblr Ubiquity", | |
group : group, | |
name : myName, | |
description : myDescription, | |
url : myTumbl | |
}, function(data) { displayMessage("Link post completed!"); }); | |
} | |
}) | |
CmdUtils.CreateCommand( { | |
name : "t-quote", | |
homepage : "http://www.tumblr.com", | |
author : { name : "Chuck Masucci", homepage : "http://www.pokenewyork.com/"}, | |
icon: "http://www.google.com/s2/favicons?domain=www.tumblr.com", | |
description : "Add quote to your Tumblog. <span id='credit'>By <a href='http://www.pokenewyork.com/'>Chuck Masucci</a></span>", | |
help : "E.g. tumblr-quote <i>this is a quote</i> title <i>johan</i>", | |
license : "MPL", | |
takes : { "tumbl" : noun_arb_text}, | |
modifiers : { "source" : noun_arb_text}, | |
preview : function(pblock, tumbl) { | |
pblock.innerHTML = "Will create a new Tumblr Quote post<br>"; | |
}, | |
execute : function(tumbl, mods) { | |
var username = Tumblr.getUsername(); | |
var password = Tumblr.getPassword(); | |
var group = Tumblr.getGroup(); | |
var myTumbl = tumbl.text; | |
var mySource = mods.source.text || ""; | |
if (!Tumblr.everythingIsOK()) { | |
displayMessage("Your email and password hasn't been set. Please use the 'tumblr-setup' command to set your email and password."); | |
return; | |
} | |
jQuery.post("http://www.tumblr.com/api/write", | |
{ email : username, | |
password : password, | |
type : "quote", | |
generator : "Tumblr Ubiquity", | |
group : group, | |
source : mySource, | |
quote : myTumbl | |
}, function(data) { displayMessage("Quote post completed!"); }); | |
} | |
}) | |
CmdUtils.CreateCommand( { | |
name : "t-photo", | |
homepage : "http://www.tumblr.com", | |
icon: "http://www.google.com/s2/favicons?domain=www.tumblr.com", | |
author : { name : "Chuck Masucci", homepage : "http://www.pokenewyork.com/"}, | |
description : "Add a photo to your Tumblog. <span id='credit'>By <a href='http://www.pokenewyork.com/'>Chuck Masucci</a></span>", | |
help : "E.g. tumblr-photo <i>photo url</i> caption <i>my caption</i> click-through-url <i>http://www.flickr.com</i>", | |
license : "MPL", | |
takes : { "tumbl" : noun_arb_text}, | |
modifiers : { "caption" : noun_arb_text}, | |
preview : function(pblock, tumbl) { | |
pblock.innerHTML = "Will create a new Tumblr Photo post<br>"; | |
}, | |
execute : function(tumbl, mods) { | |
var doc = Application.activeWindow.activeTab.document; | |
var username = Tumblr.getUsername(); | |
var password = Tumblr.getPassword(); | |
var group = Tumblr.getGroup(); | |
var myTumbl = tumbl.text; | |
var myCaption = mods.caption.text || ""; | |
if (!Tumblr.everythingIsOK()) { | |
displayMessage("Your email and password hasn't been set. Please use the 'tumblr-setup' command to set your email and password."); | |
return; | |
} | |
jQuery.post("http://www.tumblr.com/api/write", | |
{ email : username, | |
password : password, | |
type : "photo", | |
generator : "Tumblr Ubiquity", | |
group : group, | |
caption : myCaption, | |
source : myTumbl | |
}, function(data) { displayMessage("Photo post complete!"); } | |
); | |
} | |
}) | |
CmdUtils.CreateCommand( { | |
name : "t-video", | |
homepage : "http://www.tumblr.com", | |
icon: "http://www.google.com/s2/favicons?domain=www.tumblr.com", | |
author : { name : "Chuck Masucci", homepage : "http://www.pokenewyork.com/"}, | |
description : "Add a video to your Tumblog. <span id='credit'>By <a href='http://www.pokenewyork.com/'>Chuck Masucci</a></span>", | |
help : "E.g. tumblr-video <i>video url</i> caption <i>my caption</i><br> or if on a YouTube or Vimeo page, just issue: tumblr-video", | |
license : "MPL", | |
takes : { "tumbl" : noun_arb_text}, | |
modifiers : {"caption" : noun_arb_text}, | |
preview : function(pblock, tumbl) { | |
pblock.innerHTML = "Will create a new Tumblr Video post<br>"; | |
pblock.innerHTML += "Try it out: issue \"tumblr-video <i>video url</i> caption <i>my caption</i>\"<br> or if on a YouTube or Vimeo page, issue: \"tumblr-video\""; | |
}, | |
execute : function(tumbl, mods) { | |
var doc = Application.activeWindow.activeTab.document; | |
var username = Tumblr.getUsername(); | |
var password = Tumblr.getPassword(); | |
var group = Tumblr.getGroup(); | |
var myTumbl; var myCaption = mods.caption.text || ""; | |
if(myTumbl == "" || myTumbl == undefined) { | |
myTumbl = doc.location.href; | |
} | |
if(myCaption == "" || myTumbl == undefined) { | |
myCaption = ""; | |
} | |
if (!Tumblr.everythingIsOK()) { | |
displayMessage("Your email and password hasn't been set. Please use the 'tumblr-setup' command to set your email and password."); | |
return; | |
} | |
jQuery.post("http://www.tumblr.com/api/write", | |
{ email : username, | |
password : password, | |
type : "video", | |
generator : "Tumblr Ubiquity by Chuck v0.1", | |
group : group, | |
caption : myCaption, | |
embed : myTumbl | |
}, function(data) {displayMessage("Video post complete!"); } | |
); | |
} | |
}) | |
CmdUtils.CreateCommand( { | |
name : "t-setup", | |
homepage : "http://www.tumblr.com", | |
author : { name : "Chuck Masucci", homepage : "http://www.pokenewyork.com/"}, | |
icon: "http://www.google.com/s2/favicons?domain=www.tumblr.com", | |
description : "Set your Tumblr email, password. For use with the 'tumblr' command. <span id='credit'>By <a href='http://www.pokenewyork.com/'>Chuck Masucci</a></span>", | |
help : "E.g. tumblr-setup <i>username</i> pass <i>password</i>", | |
license : "MPL", | |
takes : { username : noun_arb_text}, | |
modifiers : {"pass" : noun_arb_text}, | |
preview : function(pblock, tumbl) { | |
pblock.innerHTML = "Will set your Tumblr email, password."; | |
}, | |
execute : function(data, mods) { | |
var username = data.text; | |
var password = mods.pass.text; | |
if(username.length < 1) { | |
displayMessage("This command requires a Tumblr email."); return; } | |
else if(password.length < 1) { | |
displayMessage("This command requires a Tumblr password."); return; } | |
Tumblr.addUsername(username); | |
Tumblr.addPassword(password); | |
if(Tumblr.everythingIsOK()) displayMessage("Your email, password have been set."); | |
} | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment