Your friends at Viget present Extend, a Code & Technology Blog

Radarb: A Ruby Gem That Makes Using the Outside.in API Simple

What is outside.in?

Outside.in is a hyperlocal news and information service:

Hyperlocal means news and information on a level beyond what traditional media provides. Until now, most "local" sites didn’t actually get more, well, local than cities or towns. They assumed that just because you live in a specific city or town you are looking for the same news as everyone else. Hyperlocal content gives you the news and information for the area right around where you are, like the block around your office or the neighborhood where you live.

What is outside.in Radar?

outside.in Radar is the first local news experience that puts you at the center of the action. It is customized to exactly where you are and what’s going on right around you.

Examples include tweets, news stories, and blog posts in your immediate area (surrounding blocks or neighborhoods).

What is the outside.in Radar API?

The outside.in API is a means by which developers can easily integrate Radar results into their own applications. Send it a latitude and longitude and get back stories, tweets, and other outside.in user-generated content for the surrounding area. A sample query returns XML that looks like:

<radars xmlns:georss="http://www.georss.org/georss">
  <radar type="Story">
    <item_id>2319951</item_id>
    <icon_path>http://outside.in/images/radar_icons/news.png</icon_path>
    <author>NBC New York</author>
    <author_url>http://outside.in/redirect?url=http://author.example.com</author_url>
    <published_at>Fri Dec 19 11:03:15 -0800 2008</published_at>
    <title>Drink by Fireside</title>
    <body>Ok, so it's a snowy, cold Friday night.  But that doesn't mean you need to stay in...</body>
    <url>http://outside.in/redirect?url=http://www.example.com</url>
    <places>
      <place>
        <id>43199</id>
        <name>Elizabeth</name>
        <url>http://outside.in/places/elizabeth-new-york</url>
        <georss:point>40.723944 -73.993902</georss:point>
      </place>
      <place>
        <id>62893</id>
        <name>Camp</name>
        <url>http://outside.in/places/camp-brooklyn</url>
        <georss:point>40.685733 -73.991139</georss:point>
      </place>
    </places>
  </radar>
</radars>

Why?

We recently launched a Rails-based real estate search application and wanted to add some location specific content to the page that displays details about a particular listing.

Usage

  require 'radarb'
  r = Radarb::Radar.new('40.714550', '-74.007124')
  r.blips.length     # blips are either tweets or stories
  r.stories.length   # just the story blips
  r.tweets.length    # just the tweet blips

  r.blips.collect(&:author)
  r.blips.collect {|b| b.places.first.name }
  r.blips.select  {|b| !b.tags.empty? }.collect{|b| b.tags.first.name}

Future Enhancements

The Radar API poses a challenge in terms of automatically mapping methods to collections. For example, place nodes exist under a places node which is exposed as r.places.places[0]. In radarb, the driving means behind mapping nested collection nodes without this redundancy hinges on checking for a trailing 's' character in the node name. Adding ActiveSupport as a dependency and using the Inflector to determine if certain tags are really plural might provide a more robust auto-mapping mechanism. Another possible solution is to modify HappyMapper to support passing options about nesting nodes via has_many. I'm also curious to know if any Ruby XML wrappers already exist that solve this problem.

For more information on the radarb gem check out the project on github.


Get More From Viget

Subscribe to get our monthly newsletter and occasional special announcements.