Permalink
Browse files

initial import

  • Loading branch information...
0 parents commit 11637bacceebfeb1c3af3a6bfc6f4b96232c65b2 @igrigorik committed Jun 28, 2009
Showing with 79 additions and 0 deletions.
  1. +9 −0 lib/pubsubhubbub.rb
  2. +32 −0 lib/pubsubhubbub/client.rb
  3. +38 −0 test/test_client.rb
@@ -0,0 +1,9 @@
+$:.unshift(File.dirname(__FILE__) + '/../lib')
+
+require "rubygems"
+require "eventmachine"
+require "em-http"
+
+%w[ client ].each do |file|
+ require "pubsubhubbub/#{file}"
+end
@@ -0,0 +1,32 @@
+# TODO: need header stuffs
+# ....
+
+module EventMachine
+ class PubSubHubBub
+ include EventMachine::Deferrable
+
+ def initialize(hub)
+ @hub = hub.kind_of?(URI) ? hub : URI::parse(hub)
+ end
+
+ # Publish one or more URLs to a hub.
+
+ def publish(feed)
+ data = {'hub.url' => feed, 'hub.mode' => 'publish'}
+
+ r = EventMachine::HttpRequest.new(@hub).post :body => data
+ r.callback {
+ if r.response_header.status == 204
+ succeed r
+ else
+ fail r
+ end
+ }
+
+ r.errback { fail }
+ r
+ end
+
+ end
+end
+
@@ -0,0 +1,38 @@
+require 'rubygems'
+require 'spec'
+require 'eventmachine'
+require 'lib/pubsubhubbub'
+
+describe EventMachine::PubSubHubBub do
+
+ def failed
+ EventMachine.stop
+ fail
+ end
+
+ it "should publish single feed to hub" do
+ EventMachine.run {
+ pub = EventMachine::PubSubHubBub.new('http://pubsubhubbub.appspot.com/publish').publish "http://www.test.com/"
+
+ pub.errback { fail }
+ pub.callback {
+ pub.response_header.status.should == 204
+ EventMachine.stop
+ }
+ }
+ end
+
+ it "should publish multiple feeds to hub" do
+ EventMachine.run {
+ feeds = ['http://www.test.com', 'http://www.test.com/2']
+ pub = EventMachine::PubSubHubBub.new('http://pubsubhubbub.appspot.com/publish').publish feeds
+
+ pub.errback { fail }
+ pub.callback {
+ pub.response_header.status.should == 204
+ EventMachine.stop
+ }
+ }
+ end
+
+end

0 comments on commit 11637ba

Please sign in to comment.