Serving ‘OSM-JSON’ alongside XML from the OpenStreetMap Rails port

OpenStreetMap.org‘s RESTful API allows anyone to access data on their continually growing collaborative map of the world… in XML. This is great for most applications, but if you’re working in JavaScript (as we are), XML might as well be greek. We need JSON.

To offer OSM-JSON along with of OSM-XML, we added a route to accept a “.format” suffix, and split up the render call based on the params[:format] part of the route:

# /config/routes.rb:46-50

map.connect "api/#{API_VERSION}/geohash/:geohash.:format", :controller => 'api', :action => 'geohash'
map.connect "api/#{API_VERSION}/geohash/:geohash", :controller => 'api', :action => 'geohash'

map.connect "api/#{API_VERSION}/map.:format", :controller => 'api', :action => 'map'
map.connect "api/#{API_VERSION}/map", :controller => 'api', :action => 'map'

Notice we also added a ‘geohash’ route. Whereas the /map call requires a bbox parameter (‘bbox=min_lon,min_lat,max_lon,max_lat’), we can use a geohash (Geohash in JavaScript, Geohash in Rails) which defines a bounding box as a sequence of letters and numbers. This fits Cartagen’s needs well, and since it doesn’t require any parameters, we can page cache it in Rails. (Remember that page caching bypasses Rails entirely, letting Apache handle these cached files at high speed – that saved us when we were on BoingBoing).

Continue reading “Serving ‘OSM-JSON’ alongside XML from the OpenStreetMap Rails port”

Batch importing text messages from Twitter in Rails

Here we actually batch import the messages, saving them in a local model. I also demonstrate a script to perform the imports, and set up a table to store key:value pairs for more advanced usage – I’ll finish that feature up in a subsequent tutorial.

Saving the messages locally is important for not exceeding the Twitter rate limit, as well as for performing more complex searches and manipulations with the data. It also provides a common message storage if you’re importing from multiple sources, say, FrontlineSMS, Clickatell, and Twitter.


WHOOZ Tutorial: Importing text messages from Twitter to Ruby on Rails.

Download the code for this tutorial here: whooz-messages-table-batch-importing.zip (LGPL 3.0) or on Google Code

This builds on the code written in the last tutorial, Sending and receiving text messages in Rails with Twitter

I know this is pretty low resolution, but I’ll upload an HD version next week; Vimeo allows only one HD clip per week.

Sending and receiving text messages in Rails with Twitter

In this tutorial I cover how to set up a basic Ruby on Rails 2.2.2 application and how to connect it to the Twitter API. Then I demonstrate receiving and sending Tweets, i.e. text messages through Twitter. I’ve also shared the code in Google Code.


WHOOZ Tutorial: Sending and receiving text messages in Rails with Twitter

Download the code for this tutorial here: whooz-twittter-integration.zip (LGPL 3.0)

This code requires Rails 2 – if you have OS X 10.5, it ships with 1.2; you can upgrade with the commands sudo gem update --system and sudo gem install rails