Skip to content

Instantly share code, notes, and snippets.

@superfeedr
Created August 6, 2010 10:53
Show Gist options
  • Select an option

  • Save superfeedr/511166 to your computer and use it in GitHub Desktop.

Select an option

Save superfeedr/511166 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'simplegeo'
require 'sinatra'
require 'nokogiri'
#set :port, 8084
SimpleGeo::Client.set_credentials('', '')
# Accepts subscriptions vcerification and unsubscription verification
get '/ok' do
params['hub.challenge']
end
post '/ok' do
# Parse the ATOM
xml = Nokogiri::XML(request.body.read)
xml.xpath("/atom:feed/atom:entry", {"atom" => "http://www.w3.org/2005/Atom"}).each do |entry|
point = entry.at_xpath("./geo:point", {"geo" => "http://www.georss.org/georss"})
if !point.nil?
title = entry.at_xpath("./atom:title", {"atom" => "http://www.w3.org/2005/Atom"}).text
link = entry.at_xpath("./atom:link[@rel='alternate']", {"atom" => "http://www.w3.org/2005/Atom"})["href"]
id = entry.at_xpath("./atom:id", {"atom" => "http://www.w3.org/2005/Atom"}).text
lat, lon = point.text.split(" ")
puts title
record = SimpleGeo::Record.new({
:id => id,
:created => Time.now,
:lat => lat,
:lon => lon,
:layer => 'com.superfeedr.firehose.buzz',
:properties => {
:title => title,
:link => link
}
})
SimpleGeo::Client.add_record(record)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment