Rod Waldhoff's Weblog  

< Friday, 21 November 2003 >
Ruby Userland #

As I previously mentioned, I've been toying with custom clients to the XmlStorageSystem XML-RPC protocol used by Radio Userland and several open source blog servers, with the ultimate goal of hosting a custom blog on the radio.weblogs.com host.

Over the past couple of evenings I've hacked out xmlStorageSystem.rb, a reasonably functional Ruby-based client to the XmlStorageSystem system protocol. It works like this:

To create a new instance of the client, use:

XmlStorageSystem.new(<usernumber>,<md5-hash-of-password>,<root-directory>)

For instance, I use:

XmlStorageSystem.new('122027','8c8034f5c9d68564e155c67a6d4e4612','/0122027/')

although that's not my actual password.

Actually, my local copy of xmlStorageSystem.rb has these value specified as the defaults, so I just user XmlStorageSystem.new, and I'll use that form in the rest of these examples. The constructor also accepts an number of arguments that should allow one to connect to the Python Community Server and others, although Radio is the only server I've tried.

To get a listing of the files currently stored on the server, use:

XmlStorageSystem.new.getMyDirectory

To download all those files to a local directory

XmlStorageSystem.new.backupMyDirectory 'backupdir'

To upload a file (or files) to the server, use:

XmlStorageSystem.new.saveMultipleFiles( 'local-base-dir', [ 'file1', 'file2', 'etc' ])

To delete a file (or files) from the server, use:

XmlStorageSystem.new.deleteMultipleFiles( [ 'file1', 'file2', 'etc' ])

Finally, the really handy one:

XmlStorageSystem.new.updateFromLocalDirectory 'localdir'

Which will compare the list of files in the local directory with those on the server, delete the ones that don't appear locally, and load/update the rest.

Since this is Ruby, it's easy to set up little shell scripts that invoke those commands in ways useful to your personal work style.

If one wanted to be clever, there is metadata available via XmlStorageSystem.getMyDirectory that would allow one to determine whether or not a file has changed since it was last uploaded, but I haven't gotten around to that yet.

I'm still pretty much a Ruby neophyte, so there's probably substantial room for improvement there. In particular, (1) there's no error handling present just yet and (2) the current implementation supports hackablity (changing the script itself) more than extensibility. Nevertheless, it's neat that a Ruby neophyte can write a basic XmlStorageSystem client in 150 lines of readable code.