Crowley Code! 
 (Take 12)

Uploadr extension extensions 2008/09/07

Getting re-acquainted with Flickr Uploadr, I discovered a sorely missing piece of the Extension API.  There are plenty of hooks to catch higher-level events than clicks and mouseovers — things like logins, uploads and adding photos.  However, there is no way to store persistent data and associate it with a certain Flickr user.  Here is a way:

var userinfo = {
	set: function(k, v) {

		// Only allow userinfo if they're signed into Flickr
		if (!users.nsid) { return false; }

		// It's just a hash for storing whatever you want
		var u = users.list[users.nsid];
		u.userinfo = u.userinfo || {};
		u.userinfo[k] = v;

		return true;
	get: function(k) {
		if (!users.nsid) { return undefined; }
		if (!users.list[users.nsid].userinfo) { return undefined; }
		return users.list[users.nsid].userinfo[k];
	unset: function(k) {
		if (!users.nsid) { return true; }
		if (!users.list[users.nsid].userinfo) { return true; }
		delete users.list[users.nsid].userinfo[k];
		return true;

Another thing I found missing was an after_logout event.  So I monkeypatched one:

users.old_logout = users.logout;
users.logout = function(save) {
extension.after_logout = new extension.Handler();

extension.after_logout.add(function() {

T-minus five days and I've got my development environment ready to go. I'll be at Yahoo! Open Hack Day September 12-13 in Sunnyvale, hacking on Uploadr.  Hopefully others will join me in creating some cool extensions.  Stop by and say hello.

Comments (0)

Richard Crowley?  Kentuckian engineer who cooks and eats in between bicycling and beering.

I blog mostly about programming and databases.  Browse by month or tag.

To blame for...

© 2009 Richard Crowley.  Managed by Bashpress.