Posted: 12 August 2010, 19:27
Updated: 12 August 2010, 22:39

 Subscribe via RSS

RSS, Wuala, and Perpetual Refactoring

Wuala RSS iGoogle screen shot

This article was originaly going to describe how to quickly code an RSS view of a Wuala folder. Unfortunately "feature creep" can wreak havoc on personal projects because, unlike the real world where schedule is paramount, at home I am beholden to nothing other than the desire to get something out there. In this case, I completed the core code over three months ago. The remaining time was spent fiddling, extending and refactoring. By the time I was done I had crept from a simple PHP script, to a mashup of RSS, JSON, JSONP, jQuery, Google feeds, Apache tweaks, and more CSS than I ever want to see again. The result is a fairly stable service that will hopefully not be obsoleted by a Wuala update in the next six months.

RSS is a universal format that allows users and applications to "subscribe" to things that change. Wuala provides a powerful file-sharing ecosystem that is easily accessible through a desktop client. Joining the two would allow users and applications to receive a notification that something has changed in a specific Wuala folder. With this service in place, many new tools and applications are now possible.

Table Of Contents

  1. What It Does
  2. Sample RSS Viewer
  3. Technical Details
  4. Downloads & References

What It Does

Google Reader view of a Wuala RSS feed
Google Reader view of a Wuala RSS feed

The Wuala client already provides a tab for updated or new content but it is somewhat unwieldy as it joins all updates into a single view. I wanted an alternate method of viewing changes to folder that would be usable from a variety of applications. Using Wuala's XML API I created a service that allows a user to generate an RSS feed for any folder (or sub-folder). The feed generator is written in PHP and is currently hosted on wuala.irondojo.com.

  • Some possible uses of this feed are:
  • Watch for updates to the offical Wuala Client
  • Alert friends and family members to new photos
  • Allow non-Wuala users to be notified when new content is available
  • Use as the foundation of a folder synchronization tool
  • Embed near-realtime updates in a webpage using the JSONP mode
  • Utilize an RSS to SMS bridge to receive alerts via text message

The feed API is simple:

  1. Select the folder (or sub-folder) that you want to monitor
  2. Prepend http://wuala.irondojo.com/feed to the folder path.
  3. Add this URL to any RSS 2.0 compliant reader

Optional URL Parameters:

Name Default Value Description
key null Shared key used to access private/shared Wuala folders.
See limitations for details on security.
mode rss Sets the return type. {rss|json}
callback null Sets the JavaScript callback function for use in a JSONP call. Used when mode is json
limit null Sets the maximum number of items to return.

Sample RSS Viewer

Using the new RSS service, I created a dynamic view which shows one possible method of accessing and displaying new items. I combined Google's Feed API and a little bit of jQuery to mimic a full-featured RSS reader the operates completely within the browser and requires no special server support. This code could be inserted into an existing website to implement a live news feed or photo stream.

Select a sample feed below or enter your own and click on Fetch Feed Results
Wuala Client Release Notes
Astronomy Picture of the Day Mirror

Path Key (Optional)
    Item Title Publication Date

View the source code for the Sample RSS Viewer.


Technical Details

As I mentioned in the summary, "feature creep" delayed the publication of this article for several months. Combine this with the fact that I am not an expert in any of these technologies and you have a fragmented and buggy development process. Also, I know that this is sketchy code at best. If you want to tell me a better way to do something, or to recommend that I use two spaces instead of four, feel free to add a comment at the end.

  • Simplified development process outline:
  • Basic RSS script written in PHP using Wuala's PHP API
  • tested with Google Reader
  • added RewriteRule to .htaccess for cleaner URL
  • created AJAX based reader with jQuery and Google Feed API
  • refactored core code to use Savant3 PHP templates
  • added new JSON template
  • refactored core code to support additional modes
  • added JSONP support
  • created JSONP demo
  • played with code syntax highlighter, repeatadly breaking a fixing it
  • created Python based "Astronomy Picture of the Day" mirror script for demo purposes

Feed Formats

The service returns XML or JSON depending on the mode parameter (defaults to rss). The XML format is RSS 2.0 compliant.

The JSON format is based on Google's Feed API format. This should allow a developer to swap out Google's library and still reuse their display code.

Both formats return an HTML image tag in the content field if the file type is a JPEG. The source attribute is set to the image thumbnail parameter returned from the Wuala API call.


Apache .htaccess

Adding a RewriteRule to the .htaccess file creates a cleaner interface to the service. Instead of http://wuala.irondojo.com/feed.php?path=my_folder/sub_folder you have http://wuala.irondojo.com/feed/my_folder/sub_folder.

RewriteEngine on
RewriteRule ^(.*)$ /feed.php?path=$1 [L]

JSONP Demo

JSONP is modified JSON format that allows a site to bypass the same origin policy that normaly limits AJAX requests. The JavaScript code below uses jQuery.getJSON() to load the most recent release notes from Wuala.

$.getJSON(
  'http://wuala.irondojo.com/feed/Wuala/Release%20Notes/?mode=json&callback=?',
  function(data) {
    var s = data.feed.entries.length + " entries found [" + data.feed.title + "]\n\n";
    for (var i in data.feed.entries)
      s += i + " * " + data.feed.entries[i].publishedDate + ": " +
        data.feed.entries[i].title + '\n\n';
    alert(s);
  }
);

Limitations & Caveats

Becuase the service queries Wuala's API in real time on every request, I limit the number of remote calls per request to 50. A more responsible method might be to cache results for each directory and set an expiration date for each of them after a set period of time. I could also handle reccuring or popular feeds with a single background process.

If you create a feed that uses a secret key, remember that the entire URL is sent in the clear to irondojo.com without SSL. It is also possible that my webhost could expose server logs that would contain your secret key. If you want to use this for really private data, then install the service on your own server and access it with SSL.

I currently don't monitor the accesses frequency to the service. Be nice. Don't make a request every 5 seconds. Once every thirty minutes is a good interval. A better solution would be to use Google's FeedBurner service which, in this case, would give you an itermediate caching mechanism.


Downloads & References

By Jonathan Last updated: 12 August 2010, 22:39

© irondojo · 2010 · Jonathan Camp