Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit bfd0c575e7511004ef917e64222cc4cc622a8928 1 parent 35fc0ed
Ilya Grigorik authored March 09, 2011
25  Rakefile
... ...
@@ -1,20 +1,9 @@
1  
-require 'rake'
  1
+require 'bundler'
  2
+Bundler::GemHelper.install_tasks
2 3
 
3  
-begin
4  
-  require 'jeweler'
5  
-  Jeweler::Tasks.new do |gemspec|
6  
-    gemspec.name = "pubsubhubbub"
7  
-    gemspec.summary = "Asynchronous PubSubHubbub client for Ruby"
8  
-    gemspec.description = gemspec.summary
9  
-    gemspec.email = "ilya@igvita.com"
10  
-    gemspec.homepage = "http://github.com/igrigorik/pubsubhubbub"
11  
-    gemspec.authors = ["Ilya Grigorik"]
12  
-    gemspec.add_dependency('eventmachine', '>= 0.12.9')
13  
-    gemspec.add_dependency('em-http-request', '>= 0.1.5')
14  
-    gemspec.rubyforge_project = "pubsubhubbub"
15  
-  end
  4
+require 'rspec/core/rake_task'
16 5
 
17  
-  Jeweler::GemcutterTasks.new
18  
-rescue LoadError
19  
-  puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
20  
-end
  6
+desc "Run all RSpec tests"
  7
+RSpec::Core::RakeTask.new(:spec)
  8
+
  9
+task :default => :spec
6  lib/pubsubhubbub.rb
... ...
@@ -1,10 +1,8 @@
1 1
 $:.unshift(File.dirname(__FILE__) + '/../lib')
2 2
 
3  
-require "rubygems"
4 3
 require "eventmachine"
5 4
 require "em-http"
6 5
 require "cgi"
  6
+require "uri"
7 7
 
8  
-%w[ client ].each do |file|
9  
-  require "pubsubhubbub/#{file}"
10  
-end
  8
+require "pubsubhubbub/client"
6  lib/pubsubhubbub/client.rb
@@ -7,6 +7,7 @@
7 7
 module EventMachine
8 8
   class PubSubHubbub
9 9
     include EventMachine::Deferrable
  10
+    include EventMachine::HttpEncoding
10 11
 
11 12
     HEADERS = {"User-Agent" => "PubSubHubbub Ruby", "Content-Type" => "application/x-www-form-urlencoded"}
12 13
 
@@ -17,7 +18,7 @@ def initialize(hub, options={})
17 18
 
18 19
     def publish(*feeds)
19 20
       data = feeds.flatten.collect do |feed|
20  
-        {'hub.url' => feed, 'hub.mode' => 'publish'}.to_params
  21
+        form_encode_body({'hub.url' => feed, 'hub.mode' => 'publish'})
21 22
       end.join("&")
22 23
 
23 24
       request(:body => data, :head => @headers)
@@ -31,7 +32,8 @@ def unsubscribe(feed, callback, options = {}); command('unsubscribe', feed, call
31 32
 
32 33
     def command(cmd, feed, callback, options)
33 34
       options['hub.verify'] ||= "sync"
34  
-      params = {'hub.topic' => feed, 'hub.mode' => cmd, 'hub.callback' => callback}.merge(options).to_params
  35
+      params = {'hub.topic' => feed, 'hub.mode' => cmd, 'hub.callback' => callback}.merge(options)
  36
+      params = form_encode_body(params)
35 37
 
36 38
       request(:body => params, :head => @headers)
37 39
     end
5  lib/pubsubhubbub/version.rb
... ...
@@ -0,0 +1,5 @@
  1
+module EventMachine
  2
+  class PubSubHubbub
  3
+    VERSION = '0.2.0'
  4
+  end
  5
+end
15  spec/client_spec.rb
... ...
@@ -1,5 +1,4 @@
1  
-require 'rubygems'
2  
-require 'spec'
  1
+# require 'rubygems'
3 2
 require 'eventmachine'
4 3
 require 'lib/pubsubhubbub'
5 4
 
@@ -13,7 +12,7 @@ def failed
13 12
   describe "protected hub" do
14 13
     it "should accept basic auth options" do
15 14
 
16  
-      EventMachine::HttpRequest.should_receive(:new).and_return(req = mock('request',:null_object=>true))
  15
+      EventMachine::HttpRequest.should_receive(:new).and_return(req = mock('request').as_null_object)
17 16
       req.should_receive(:post).with(
18 17
         :body => anything,
19 18
         :head => hash_including(
@@ -57,23 +56,23 @@ def failed
57 56
       }
58 57
     }
59 58
   end
60  
-  
  59
+
61 60
   it "should subscribe a single feed to hub" do
62 61
     EventMachine.run {
63 62
       sub = EventMachine::PubSubHubbub.new('http://pubsubhubbub.appspot.com/').subscribe "http://blog.superfeedr.com/atom.xml", "http://superfeedr.com/hubbub", {}
64  
-      
  63
+
65 64
       sub.errback { failed }
66 65
       sub.callback {
67 66
         sub.response_header.status.should == 204
68 67
         EventMachine.stop
69 68
       }
70  
-    }    
  69
+    }
71 70
   end
72  
-  
  71
+
73 72
   it "should unsubscribe a single feed to hub" do
74 73
     EventMachine.run {
75 74
       sub = EventMachine::PubSubHubbub.new('http://pubsubhubbub.appspot.com/').unsubscribe "http://blog.superfeedr.com/atom.xml", "http://superfeedr.com/hubbub", {}
76  
-      
  75
+
77 76
       sub.errback { failed }
78 77
       sub.callback {
79 78
         sub.response_header.status.should == 204

0 notes on commit bfd0c57

Please sign in to comment.
Something went wrong with that request. Please try again.