Rack Middleware for Superfeedr

Rack Middleware for Superfeedr

I am a bit ashamed that this comes so late… but it’s always better late than never: we have a rack middleware for Superfeedr.

What it does is simple: subscribe, unsubscribe and help you handle notifications by hiding all the PubSubHubbub -complexity- magic. Since it’s Rack, it should work with any Ruby web framework that supports Rack, including Rails and Sinatra.

require 'sinatra'
require 'rack-superfeedr'

use Rack::Superfeedr, { :host => "plant-leg.showoff.io", :login => "demo", :password => "demo", :format => "json", :async => false } do |superfeedr|
  set :superfeedr, superfeedr # so that we can use `settings.superfeedr` to access the superfeedr object in our application.
  
  superfeedr.on_notification do |notification|
    puts notification.to_s # You probably want to persist that data in some kind of data store...
  end
  
end

get '/hi' do
  "Hello World!" # Maybe serve the data you saved from Superfeedr's handler.
end

get '/subscribe' do
  settings.superfeedr.subscribe("http://push-pub.appspot.com/feed") 
end

get '/unsubscribe' do
  settings.superfeedr.unsubscribe("http://push-pub.appspot.com/feed")
end

Get it while it’s hot: gem install rack-superfeedr, and check the code on github. If you build something awesome, please let us know and we’ll link to it.

As you can see it’s quite elegant :)

Update: if you’re using a Rails application, we suggest you use this Superfeedr Engine as it will handle a lot more things on your behalf.

Liked this post? Read the archive or

On the same topic, check sinatra, heroku and superfeedr, consuming rss feeds in rails application and async notification replays.

Previously, on the Superfeedr blog: Publish Subscribe for the web.