I started working on a project over the weekend to pull together a demonstration of using Ruby, and RSS or Atom and Web services. I also want to add Artix and it's Data Services into the mix later. The final result will be a mashup but I want to start publishing some of the work as I go along.
I hadn't worked with Ruby before. I had alrady started learning PHP but was encouraged by Steve Vinoski to start looking at Ruby. Jim Watson and Greg Lomow, whom I had worked with developing a language back in 1997, finally convinced me. So I bought two books: Ruby Cookbook and Programming Ruby The Pragmatic Programmers' guide. I then loaded up a bunch of bookmarks in my browser of Ruby sites and off I went.
Then it was off to work on some code.
First I built a couple of classes to write an atom based feed - an atom.xml file. These two classes handle writing out the feed header information and then each of the entries.
Then I decided to make some Web services calls to a stock quote web service to get some quotes. I added an entry to the feed for each symbol and it's results. I placed the results in some XML into the content element of the atom feed entry.
I added an array of symbols for looking up and then ran it. This is pretty simple stuff and Ruby makes it even simpler. I'm sure some experienced Ruby people might point out some improvements.
Some observations:
- I was going to use a reflection based
approach to building the XML from the attributes in the class instance
but Ruby treats attributes like a hash table (as far as I can tell) and
therefore the order you declare them does not necessarily mean they'll
be listed back in that order.
- Looking at libraries like REXML made me think that XML isn't something Ruby does well - one of the books (Cookbook?) suggested that too.
- My browser (Safari) stripped out the XML tags from the XML fragment that I put in the content element. I was going to try and fix this but then thought that it really doesn't matter - my example is really for something other than a browser to be consuming this feed.
- The Web service I used is what you would call fine-grained in that I couldn't send up a list of Symbols but instead had to make a call for each symbol. The better way would be to make one call and then iterate through the results to build the feed entries.
As I develop this I'll probably change from using stock quotes. In the meantime I'm going to add a database at the back to store some information relating to the symbols.
I think a combination of languages like Ruby and Web services and RSS/Atom can build powerful applications. Add products like Artix to get at back end legacy services that don't support SOAP/HTTP and you can see how powerful this can be.
So for the moment it's pretty simple. But it was fun. You can download the Ruby here. If your browser supports atom feeds then you can view the results or just download/view the atom.xml file.
LATER: I found a bug and fixed it. I was forgetting the last </feed>
tag. (duh!) I noticed that Safari didn't mind but Firefox was having
trouble. FYI atom feed readers don't seem be standard with Firefox.
There are a number of readers you can download for it but I've had
trouble with the two I tried. Firefox will show you the feed XML now if
you were having trouble earlier. I have not tested this with Internet
Explorer on Windows.

IP Babble is the personal blog of William Henry.
Leave a comment