Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

make compatible with latest em-http + update to use Bundler

  • Loading branch information...
commit bfd0c575e7511004ef917e64222cc4cc622a8928 1 parent 35fc0ed
@igrigorik authored
View
25 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
View
6 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"
View
6 lib/pubsubhubbub/client.rb
@@ -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"}
@@ -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)
@@ -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
View
5 lib/pubsubhubbub/version.rb
@@ -0,0 +1,5 @@
+module EventMachine
+ class PubSubHubbub
+ VERSION = '0.2.0'
+ end
+end
View
15 spec/client_spec.rb
@@ -1,5 +1,4 @@
-require 'rubygems'
-require 'spec'
+# require 'rubygems'
require 'eventmachine'
require 'lib/pubsubhubbub'
@@ -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(
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.