pubsubhubbub 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile CHANGED
@@ -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
@@ -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"
@@ -7,19 +7,21 @@
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
 
13
- def initialize(hub)
14
+ def initialize(hub, options={})
15
+ @headers = HEADERS.merge(options[:head]) if options[:head]
14
16
  @hub = hub.kind_of?(URI) ? hub : URI::parse(hub)
15
17
  end
16
18
 
17
19
  def publish(*feeds)
18
20
  data = feeds.flatten.collect do |feed|
19
- {'hub.url' => feed, 'hub.mode' => 'publish'}.to_params
21
+ form_encode_body({'hub.url' => feed, 'hub.mode' => 'publish'})
20
22
  end.join("&")
21
23
 
22
- request(:body => data, :head => HEADERS)
24
+ request(:body => data, :head => @headers)
23
25
  end
24
26
 
25
27
  # These command will work only if the callback URL supports confirmation.
@@ -28,31 +30,31 @@ module EventMachine
28
30
 
29
31
  private
30
32
 
31
- def command(cmd, feed, callback, options)
32
- options['hub.verify'] ||= "sync"
33
- params = {'hub.topic' => feed, 'hub.mode' => cmd, 'hub.callback' => callback}.merge(options).to_params
33
+ def command(cmd, feed, callback, options)
34
+ options['hub.verify'] ||= "sync"
35
+ params = {'hub.topic' => feed, 'hub.mode' => cmd, 'hub.callback' => callback}.merge(options)
36
+ params = form_encode_body(params)
34
37
 
35
- request(:body => params, :head => HEADERS)
36
- end
38
+ request(:body => params, :head => @headers)
39
+ end
37
40
 
38
- def request(opts)
39
- r = http_request(opts)
41
+ def request(opts)
42
+ r = http_request(opts)
43
+ r.errback { fail }
40
44
 
41
- r.callback do
42
- if r.response_header.status == 204
43
- succeed r
44
- else
45
- fail r
46
- end
45
+ r.callback do
46
+ if r.response_header.status == 204
47
+ succeed r
48
+ else
49
+ fail r
47
50
  end
48
-
49
- r.errback { fail }
50
- r
51
-
52
51
  end
53
52
 
54
- def http_request(opts)
55
- EventMachine::HttpRequest.new(@hub).post opts
56
- end
53
+ r
54
+ end
55
+
56
+ def http_request(opts)
57
+ EventMachine::HttpRequest.new(@hub).post opts
58
+ end
57
59
  end
58
60
  end
@@ -0,0 +1,5 @@
1
+ module EventMachine
2
+ class PubSubHubbub
3
+ VERSION = '0.2.0'
4
+ end
5
+ end
@@ -1,5 +1,4 @@
1
- require 'rubygems'
2
- require 'spec'
1
+ # require 'rubygems'
3
2
  require 'eventmachine'
4
3
  require 'lib/pubsubhubbub'
5
4
 
@@ -10,6 +9,29 @@ describe EventMachine::PubSubHubbub do
10
9
  fail
11
10
  end
12
11
 
12
+ describe "protected hub" do
13
+ it "should accept basic auth options" do
14
+
15
+ EventMachine::HttpRequest.should_receive(:new).and_return(req = mock('request').as_null_object)
16
+ req.should_receive(:post).with(
17
+ :body => anything,
18
+ :head => hash_including(
19
+ 'authorization'=> ['username','password']
20
+ )
21
+ ).and_return(req)
22
+ req.stub!(:callback) {EventMachine.stop}
23
+
24
+ EventMachine.run {
25
+ pub = EventMachine::PubSubHubbub.new('http://example.com/hub', :head => {'authorization' => ['username','password']})
26
+ pub.subscribe 'http://example.com/feed', 'http://example.com/callback'
27
+ pub.callback {
28
+ sub.response_header.status.should == 204
29
+ EM.stop
30
+ }
31
+ }
32
+ end
33
+ end
34
+
13
35
  it "should publish single feed to hub" do
14
36
  EventMachine.run {
15
37
  pub = EventMachine::PubSubHubbub.new('http://pubsubhubbub.appspot.com/publish').publish "http://www.test.com/"
@@ -34,29 +56,29 @@ describe EventMachine::PubSubHubbub do
34
56
  }
35
57
  }
36
58
  end
37
-
59
+
38
60
  it "should subscribe a single feed to hub" do
39
61
  EventMachine.run {
40
62
  sub = EventMachine::PubSubHubbub.new('http://pubsubhubbub.appspot.com/').subscribe "http://blog.superfeedr.com/atom.xml", "http://superfeedr.com/hubbub", {}
41
-
63
+
42
64
  sub.errback { failed }
43
65
  sub.callback {
44
66
  sub.response_header.status.should == 204
45
67
  EventMachine.stop
46
68
  }
47
- }
69
+ }
48
70
  end
49
-
71
+
50
72
  it "should unsubscribe a single feed to hub" do
51
73
  EventMachine.run {
52
74
  sub = EventMachine::PubSubHubbub.new('http://pubsubhubbub.appspot.com/').unsubscribe "http://blog.superfeedr.com/atom.xml", "http://superfeedr.com/hubbub", {}
53
-
75
+
54
76
  sub.errback { failed }
55
77
  sub.callback {
56
78
  sub.response_header.status.should == 204
57
79
  EventMachine.stop
58
80
  }
59
- }
81
+ }
60
82
  end
61
83
 
62
84
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
8
- - 1
9
- version: 0.1.1
7
+ - 2
8
+ - 0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ilya Grigorik
@@ -14,62 +14,89 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-05-01 00:00:00 -04:00
17
+ date: 2011-03-09 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: eventmachine
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
24
25
  requirements:
25
26
  - - ">="
26
27
  - !ruby/object:Gem::Version
27
28
  segments:
28
29
  - 0
29
- - 12
30
- - 9
31
- version: 0.12.9
30
+ version: "0"
32
31
  type: :runtime
33
32
  version_requirements: *id001
34
33
  - !ruby/object:Gem::Dependency
35
34
  name: em-http-request
36
35
  prerelease: false
37
36
  requirement: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
38
  requirements:
39
39
  - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  segments:
42
42
  - 0
43
- - 1
44
- - 5
45
- version: 0.1.5
43
+ version: "0"
46
44
  type: :runtime
47
45
  version_requirements: *id002
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ prerelease: false
49
+ requirement: &id003 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ segments:
55
+ - 0
56
+ version: "0"
57
+ type: :development
58
+ version_requirements: *id003
59
+ - !ruby/object:Gem::Dependency
60
+ name: rake
61
+ prerelease: false
62
+ requirement: &id004 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ segments:
68
+ - 0
69
+ version: "0"
70
+ type: :development
71
+ version_requirements: *id004
48
72
  description: Asynchronous PubSubHubbub client for Ruby
49
- email: ilya@igvita.com
73
+ email:
74
+ - ilya@igvita.com
50
75
  executables: []
51
76
 
52
77
  extensions: []
53
78
 
54
- extra_rdoc_files:
55
- - README.rdoc
79
+ extra_rdoc_files: []
80
+
56
81
  files:
57
82
  - README.rdoc
58
83
  - Rakefile
59
84
  - VERSION
60
85
  - lib/pubsubhubbub.rb
61
86
  - lib/pubsubhubbub/client.rb
62
- - test/test_client.rb
87
+ - lib/pubsubhubbub/version.rb
88
+ - spec/client_spec.rb
63
89
  has_rdoc: true
64
90
  homepage: http://github.com/igrigorik/pubsubhubbub
65
91
  licenses: []
66
92
 
67
93
  post_install_message:
68
- rdoc_options:
69
- - --charset=UTF-8
94
+ rdoc_options: []
95
+
70
96
  require_paths:
71
97
  - lib
72
98
  required_ruby_version: !ruby/object:Gem::Requirement
99
+ none: false
73
100
  requirements:
74
101
  - - ">="
75
102
  - !ruby/object:Gem::Version
@@ -77,6 +104,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
77
104
  - 0
78
105
  version: "0"
79
106
  required_rubygems_version: !ruby/object:Gem::Requirement
107
+ none: false
80
108
  requirements:
81
109
  - - ">="
82
110
  - !ruby/object:Gem::Version
@@ -86,9 +114,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
114
  requirements: []
87
115
 
88
116
  rubyforge_project: pubsubhubbub
89
- rubygems_version: 1.3.6
117
+ rubygems_version: 1.3.7
90
118
  signing_key:
91
119
  specification_version: 3
92
120
  summary: Asynchronous PubSubHubbub client for Ruby
93
121
  test_files:
94
- - test/test_client.rb
122
+ - spec/client_spec.rb