Displaying AudioBoos on your site

AudioBoo
Jun
21

Since the advent of Twitter's 140 character goodness, another tool often used with Twitter is becoming a new craze. That is the AudioBoo. Here we look at how you can use an AudioBoo Atom feed to display a feed of your own AudioBoos to your site.

If you've ever parsed XML before then you're going to find this very easy to implement; otherwise I hope my description of how to do this will help you. To start with, I assume you know what an AudioBoo is - it's an audio blogging application which is available for the iPhone.

Once you've found the list of AudioBoos you want to use you'll notice an ATOM feed is available for them. For example, whilst logged into my AudioBoo account I clicked on "My Boos" and then clicked on the orange RSS icon which took me to http://audioboo.fm/users/2417/boos.atom

I'm going to assume you're using PHP, but if you're not then it shouldn't be too hard to adapt for your language of choice. To start with we need to make a call to this URL so that we can store the contents in a string ready for parsing. The function I use to process this is:

/**
 * Send a request to the AudioBoo ATOM feed of choice and parse the result
 * @param integer $userid The id of the user to get AudioBoos for
 * @return array The array of retrieved AudioBoos
 */
function _getBoos ($userid)
{
   $xml = file_get_contents(AUDIOBOO_URL . $userid . '/boos.atom');
   $xml = simplexml_load_string($xml);
   $this->title = (string) $xml->title;
   $this->subtitle = (string) $xml->subtitle;
   $boos = array();
   if (!empty($xml->entry)) {
      foreach ($xml->entry as $entry) {
         $boo = new AudioBoo();
         $boo->id = (string) $entry->id;
         $boo->title = (string) $entry->title;
         $boo->summary = (string) $entry->summary;
         $boo->link = (string) $entry->link[1]->attributes()->href;
         $boo->length = (string) $entry->link[1]->attributes()->length;
         $boo->published = (string) $entry->published;
         $boo->updated = (string) $entry->updated;
         $boo->author_user = (string) $entry->author->name;
         $boo->author_url = (string) $entry->author->uri;
         $boo->content = (string) $entry->content;
         $boo->url = (string) $entry->link[0]->attributes()->href;
         $boos[] = $boo;
      }
   }
   $this->boos = $boos;
}

Please note that this is part of a class file, and AUDIOBOO_URL is defined in the same file. What this does is it takes the XML returned and converts it into a readable array using SimpleXML objects. From here we can then set the title and subtitle of the feed and then parse the entries from the feed into the "boos" array. Each entry in the boos array is an AudioBoo object which has defintions for all the required AudioBoo properties.

Looking back at the parser there a few places where you can see functions in the middle of the path to the properties - these are because the properties which follow where once attributes within the tag and are accessed slightly differently.

With the returned object we can then print a list of the AudioBoos or do whatever we like with it. If anyone would like the full class file, would like any further help, or has any suggestions then please let me know in the comments section.

your comments - Post a comment

blog comments powered by Disqus