ブログを再開するにあたり、更新情報はどこに通知するべきなんだろうとか調べていたら、GoogleもPubSubHubbubのハブを用意したようだった。PubSubHubbubについては以前にも記事を書いていた(OctopressでPubSubHubbubを有効にする方法)。

PubSubHubbub利用方法

https://pubsubhubbub.appspot.com/に説明が書いてあるので読んでみる。

Feedにタグを追加する

Add an //atom:link tag under //atom:feed for Atom feeds or under //rss:rss/channel for RSS feeds. The //atom:link tag should have rel attribute set to hub and href attribute set to https://pubsubhubbub.appspot.com/

  • <link rel="hub" href="https://pubsubhubbub.appspot.com/"/>をATOMフィードに追加する
  • <atom:link rel="hub" href="https://pubsubhubbub.appspot.com/"/>をRSSフィードに追加する

Alternatively, your feed can be served with two Link headers: one with rel attribute set to hub and href attribute set to https://pubsubhubbub.appspot.com/ one with rel attribute set to self and href attribute set to the feed URL of the feed

あるいは、フィードで2つのLinkヘッダーを送信するようにする。

  • Link: https://pubsubhubbub.appspot.com/; rel=hub
  • Link: https://blog.satooshi.jp/atom.xml; rel=self

POST先

Whenever new content is added to a feed, notify the hub. This is accomplished by sending a POST request to https://pubsubhubbub.appspot.com/ with Content-Type: application/x-www-form-urlencoded and two parameters encoded in the body: hub.mode equal to publish hub.url equal to the feed URL of the feed that has been updated. This field may be repeated to indicate multiple feeds that have been updated

  • URL: https://pubsubhubbub.appspot.com/
  • Content-Type: application/x-www-form-urlencoded
  • POSTパラメータ
    • hub.mode = 'publish'
    • hub.url = 'https://blog.satooshi.jp/atom.xml' (atom.xmlとかfeedとかのURL)

rakeタスクはこんな感じで動くはず。

desc 'notify to PuSH Hub server'
task pubsub: :environment do
atom_url = "https://blog.satooshi.jp/atom.xml"
hub_urls = ['https://satooshi.superfeedr.com', 'https://pubsubhubbub.appspot.com']
hub_urls.each do |hub_url|
resp, data = Net::HTTP.post_form(URI.parse(hub_url),
{'hub.mode' => 'publish',
'hub.url' => atom_url})
raise "Hub notification error: #{resp.code} #{resp.msg}, #{data}" unless resp.code == '204'
puts "## Notified #{atom_url} to #{hub_url}"
end
end