1,007
edits
Changes
→Twitter: Putting It All Together
= Twitter: Putting It All Together =
We've now covered everything we need to cover in order to write a command that allows us to [http://en.wikipedia.org/wiki/Twitter Twitter] from Ubiquity. The code below is the actual source code of the Twitter command as it appears in Ubiquity 0.5. Many thanks to [http://theunfocused.net/moz/ubiquity/verbs/ Blair McBride] for writing this command. This The source code is a fully functioning command: bit more intricate than anything we've seen so far, but it's built using exactly the browser takes care same basic pieces -- and demonstrates nearly all of the odd edge cases, like not being logged those pieces inaction.
<pre>
CmdUtils.CreateCommand({
var previewData = {
status: <>{statusText}</>.texttoXMLString(), username: usernameText && _("(For user <b>${usernameText}</b>)"), chars: TWITTER_STATUS_MAXLEN - statusText.text.length
};
var truncateData = {
truncate: 0 - previewData.chars
};
}
previewBlock.innerHTML = previewHTML;
},
return;
}
var updateUrl = "https://twitter.com/statuses/update.json";
var updateParams = {
source: "ubiquity",
status: statusText.text //dont cut the input since sometimes, the user selects a big url, //and the total lenght is more than 140, but tinyurl takes care of that
};
var me = this; function sendMessage() { jQuery.ajax({ type: "POST", url: updateUrl, data: updateParams, dataType: "json", error: function() { displayMessage me._show(_("Twitter error - status not updated")); }, success: function() { displayMessage me._show(/^d /.test(statusText) ? _("direct message sent") : _("Twitter status updated")); }, username: login.username, password: login.password }); } var login; var alias = args.alias; if (alias && alias.text && alias.data) { login = alias.data; sendMessage(); } else { login = {username: null, password: null}; if (alias && alias.text) login.username = alias.text; sendMessage(); } }, _show: function(txt){ displayMessage({icon: this.icon, title: this.name, text: txt});
}
});