Consuming GeoRSS Feeds with Ruby
by dbaldwin
Each device in your system has the ability to publish a “private” or “public” GeoRSS feed. This is a simple RSS feed with a geographical encoding that is easy to integrate into third party applications. For example, your Foundation server can be used to aggregate GPS data from hundreds of remote assets and integrated into a back-office system using a GeoRSS parser. By default all GeoRSS feeds are private and require HTTP authentication. The code snippet below demonstrates how to access our private GeoRSS feed using Ruby and you can download the source here. This example requires Ruby as well as the Net:HTTP and REXML libraries, both of which should come as part of the standard ruby install.
# A simple example of accessing a GeoRSS feed using HTTP authentication
# Be sure to make the global vars applicable to your Foundation server
require 'net/http'
require 'rexml/document'
# Global vars for accessing GeoRSS feeds
host = 'demo.ublip.com' # Change this to your server URL
private_path = '/readings/last/1' # Append the appropriate device ID as a parameter to the request
username = 'demo@ublip.com' # Change this to your web username
password = 'testing' # Change this to your web password
# Access the private feed over HTTP
http = Net::HTTP.new(host)
request = Net::HTTP::Get.new(private_path)
request.basic_auth(username, password)
response = http.request(request)
# Parse the response
xml = REXML::Document.new(response.body)
xmlroot = xml.root
# A demonstration of climbing down the XML tree
title = xmlroot.elements["channel"].elements["title"].text
address = xmlroot.elements["channel"].elements["item"].elements["description"].text
location = xmlroot.elements["channel"].elements["item"].elements["georss:point"].text
lat = location.split(" ")[0] # A GeoRSS point is delimited by a space
lng = location.split(" ")[1]
