From 27d8cc8003cd94efe313a11acd3fddeae3ad8c47 Mon Sep 17 00:00:00 2001 From: maxwell Date: Wed, 5 Jan 2011 18:52:24 -0800 Subject: [PATCH] added sync pubsubhubbub publisher client. we now should not longer require eventmachine, (in the server process, the websocket still requires it). this should also be in a job --- app/models/jobs/http_post.rb | 5 +++++ lib/postzord/dispatch.rb | 2 +- lib/pubsubhubbub.rb | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 lib/pubsubhubbub.rb diff --git a/app/models/jobs/http_post.rb b/app/models/jobs/http_post.rb index 16764a579..c9a58ba96 100644 --- a/app/models/jobs/http_post.rb +++ b/app/models/jobs/http_post.rb @@ -1,3 +1,8 @@ +# Copyright (c) 2010, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. + + module Jobs class HttpPost extend ResqueJobLogging diff --git a/lib/postzord/dispatch.rb b/lib/postzord/dispatch.rb index 6b927ac22..90b796517 100644 --- a/lib/postzord/dispatch.rb +++ b/lib/postzord/dispatch.rb @@ -45,7 +45,7 @@ class Postzord::Dispatch def deliver_to_hub Rails.logger.debug("event=post_to_service type=pubsub sender_handle=#{@sender.diaspora_handle}") - EventMachine::PubSubHubbub.new(AppConfig[:pubsub_server]).publish(@sender.public_url) + PubSubHubbub.new(AppConfig[:pubsub_server]).publish(@sender.public_url) end def deliver_to_services(url) diff --git a/lib/pubsubhubbub.rb b/lib/pubsubhubbub.rb new file mode 100644 index 000000000..bb0bcf2a3 --- /dev/null +++ b/lib/pubsubhubbub.rb @@ -0,0 +1,19 @@ +# Copyright (c) 2010, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. + + +class PubSubHubbub + + H = {"User-Agent" => "PubSubHubbub Ruby", "Content-Type" => "application/x-www-form-urlencoded"} + + def initialize(hub, options={}) + @headers = H.merge(options[:head]) if options[:head] + @hub = hub.kind_of?(URI) ? hub : URI::parse(hub) + end + + def publish(feed) + RestClient.post @hub, :headers => H, 'hub.url' => feed, 'hub.mode' => 'publish' + end +end +