开发者

Write a Ruby on Rails PubSubHubbub Client

I need to write an endpoint to receive pings and feeds from PSHB hub as new content is published. I know there are some libs on Ruby, like https://github.com/igrigorik/PubSubHubbub for example, but cannot figure out how to implement a Ruby on Rails callback with a reactor code like the following:

require "rubygems"
require "pubsubhubbub"

EventMachine.run {
  # pu开发者_运维技巧blish single URL
  pub = EventMachine::PubSubHubbub.new('http://pubsubhubbub.appspot.com/publish').publish "http://www.test.com/one-feed.atom"
  pub.callback { puts "Successfully notified hub." }
  pub.errback  { puts "Uh oh, something broke: #{pub.response}" }
}

thanks in advance luca


The plugin you point is dedicated to publishers. You need to write something for the "subscriber" use case.

The first thing you need to do is send HTTP POST requests to subscribe. Any HTTP client library, like typhoeus should just work fine. Check this guide to get started.

Then you need to make sure that your app can handle notifications. Create a controller to which items will be posted. You want to use a different callback for each feed, as it makes things so much easier to debug. Create a feeds controller and post to /feeds/1 for feed 1, ... etc.

The tricky part is to read the body of the HTTP notification, but I'm sure Rails allows you to use the raw body, rather than the parsed params.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜