Skip to content

Commit

Permalink
make compatible with latest em-http + update to use Bundler
Browse files Browse the repository at this point in the history
  • Loading branch information
igrigorik committed Mar 10, 2011
1 parent 35fc0ed commit bfd0c57
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 32 deletions.
25 changes: 7 additions & 18 deletions Rakefile
@@ -1,20 +1,9 @@
require 'rake'
require 'bundler'
Bundler::GemHelper.install_tasks

begin
require 'jeweler'
Jeweler::Tasks.new do |gemspec|
gemspec.name = "pubsubhubbub"
gemspec.summary = "Asynchronous PubSubHubbub client for Ruby"
gemspec.description = gemspec.summary
gemspec.email = "ilya@igvita.com"
gemspec.homepage = "http://github.com/igrigorik/pubsubhubbub"
gemspec.authors = ["Ilya Grigorik"]
gemspec.add_dependency('eventmachine', '>= 0.12.9')
gemspec.add_dependency('em-http-request', '>= 0.1.5')
gemspec.rubyforge_project = "pubsubhubbub"
end
require 'rspec/core/rake_task'

Jeweler::GemcutterTasks.new
rescue LoadError
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
end
desc "Run all RSpec tests"
RSpec::Core::RakeTask.new(:spec)

task :default => :spec
6 changes: 2 additions & 4 deletions lib/pubsubhubbub.rb
@@ -1,10 +1,8 @@
$:.unshift(File.dirname(__FILE__) + '/../lib')

require "rubygems"
require "eventmachine"
require "em-http"
require "cgi"
require "uri"

%w[ client ].each do |file|
require "pubsubhubbub/#{file}"
end
require "pubsubhubbub/client"
6 changes: 4 additions & 2 deletions lib/pubsubhubbub/client.rb
Expand Up @@ -7,6 +7,7 @@
module EventMachine
class PubSubHubbub
include EventMachine::Deferrable
include EventMachine::HttpEncoding

HEADERS = {"User-Agent" => "PubSubHubbub Ruby", "Content-Type" => "application/x-www-form-urlencoded"}

Expand All @@ -17,7 +18,7 @@ def initialize(hub, options={})

def publish(*feeds)
data = feeds.flatten.collect do |feed|
{'hub.url' => feed, 'hub.mode' => 'publish'}.to_params
form_encode_body({'hub.url' => feed, 'hub.mode' => 'publish'})
end.join("&")

request(:body => data, :head => @headers)
Expand All @@ -31,7 +32,8 @@ def unsubscribe(feed, callback, options = {}); command('unsubscribe', feed, call

def command(cmd, feed, callback, options)
options['hub.verify'] ||= "sync"
params = {'hub.topic' => feed, 'hub.mode' => cmd, 'hub.callback' => callback}.merge(options).to_params
params = {'hub.topic' => feed, 'hub.mode' => cmd, 'hub.callback' => callback}.merge(options)
params = form_encode_body(params)

request(:body => params, :head => @headers)
end
Expand Down
5 changes: 5 additions & 0 deletions lib/pubsubhubbub/version.rb
@@ -0,0 +1,5 @@
module EventMachine
class PubSubHubbub
VERSION = '0.2.0'
end
end
15 changes: 7 additions & 8 deletions spec/client_spec.rb
@@ -1,5 +1,4 @@
require 'rubygems'
require 'spec'
# require 'rubygems'
require 'eventmachine'
require 'lib/pubsubhubbub'

Expand All @@ -13,7 +12,7 @@ def failed
describe "protected hub" do
it "should accept basic auth options" do

EventMachine::HttpRequest.should_receive(:new).and_return(req = mock('request',:null_object=>true))
EventMachine::HttpRequest.should_receive(:new).and_return(req = mock('request').as_null_object)
req.should_receive(:post).with(
:body => anything,
:head => hash_including(
Expand Down Expand Up @@ -57,23 +56,23 @@ def failed
}
}
end

it "should subscribe a single feed to hub" do
EventMachine.run {
sub = EventMachine::PubSubHubbub.new('http://pubsubhubbub.appspot.com/').subscribe "http://blog.superfeedr.com/atom.xml", "http://superfeedr.com/hubbub", {}

sub.errback { failed }
sub.callback {
sub.response_header.status.should == 204
EventMachine.stop
}
}
}
end

it "should unsubscribe a single feed to hub" do
EventMachine.run {
sub = EventMachine::PubSubHubbub.new('http://pubsubhubbub.appspot.com/').unsubscribe "http://blog.superfeedr.com/atom.xml", "http://superfeedr.com/hubbub", {}

sub.errback { failed }
sub.callback {
sub.response_header.status.should == 204
Expand Down

0 comments on commit bfd0c57

Please sign in to comment.