Ruby, Atom, and Web services

| No Comments | No TrackBacks

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.

No TrackBacks

TrackBack URL: http://ipbabble.com/cgi-bin/mt/mt-tb.cgi/23

Leave a comment

Who is IPBabble

William Henry IP Babble is the personal blog of William Henry.

William has 20 years experience in software development and distributed computing and holds a M.Sc from Dublin City University. He is currently working in the office of CTO at Red Hat on the MRG product. This weblog is not funded by Red Hat.

Posts are intended to express independent points of view, but understand that there is probably a bias based on the influence of working with standards based middleware for over a decade. (See disclaimer below)

December 2008

Sun Mon Tue Wed Thu Fri Sat
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      

Disclaimer

The views expressed in this blog are solely the personal views of the author and DO NOT represent the views of his employer or any third party.

About this Entry

This page contains a single entry by William Henry published on August 22, 2006 12:04 AM.

New Celtix Based Mashup at Haute Techno was the previous entry in this blog.

Disappearing Web Services is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.