Scott Guthrie has a series of tutorials on how to consume the Digg API with Silverlight and C#. I wanted to know if I could convert that tutorial to IronRuby.
What I came up has the same end result but due to the fact that IronRuby and its Silverlight implementation isn’t complete yet I can’t mimic the structure of that tutorial yet. I couldn’t yet figure out how to load external xaml files so I put all the xaml in one file.
I have one C# file that resides in the lib folder, this file is called DigStory.cs and contains a DiggStory class which represents a story on digg. It uses XLinq to parse the xml document and return a list of stories.
I won’t post the xaml file because it’s a bit too long. I will however post the app.rb file and offer a little bit more explanation on that file.
The above code contains all the code necessary for our application.
We first tell the application to use the app.xaml file. Next we define a method that builds us the request url for the digg api. I chose to use the xml format to stay as close as possible to the sample of Scott.
Like in the C# sample we’re also downloading the file asynchronous. In the callback for when the request completes we parse the returned string into a list of stories and set that as the item source of our Listbox in the app.xaml file.
We handle the selection_changed event of the ListBox to display a detail view on a story with a link to the digg page.
More explanation on the xaml can be found on Scotts blog.
Put the path to chiron.exe in your PATH variable and extract the contents of the downloaded sample. open a command prompt and go to the location where you extracted the files to. type chiron /b and click on index.html