编写 Ruby on Rails PubSubHubbub 客户端

发布于 2024-11-08 18:52:42 字数 593 浏览 6 评论 0原文

我需要编写一个端点来在新内容发布时从 PSHB 中心接收 ping 和 feed。我知道 Ruby 上有一些库,例如 https://github.com/igrigorik/PubSubHubbub 例如,但无法弄清楚如何使用如下反应器代码实现 Ruby on Rails 回调:

require "rubygems"
require "pubsubhubbub"

EventMachine.run {
  # publish 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}" }
}

提前致谢 卢卡

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 {
  # publish 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无尽的现实 2024-11-15 18:52:42

您指向的插件专用于发布商。您需要为“订阅者”用例编写一些内容。

您需要做的第一件事是发送 HTTP POST 请求进行订阅。任何 HTTP 客户端库,例如 typhoeus 都应该可以正常工作。查看此入门指南

然后您需要确保您的应用程序可以处理通知。创建一个将向其发布项目的控制器。您希望为每个提要使用不同的回调,因为它使事情更容易调试。创建一个提要控制器并将提要 1 发布到 /feeds/1 等。

棘手的部分是读取 HTTP 通知的正文,但我确信 Rails 允许您使用原始主体,而不是解析后的参数。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文