julien51-pubsubhubbub 0.1 → 0.1.1

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.
@@ -8,6 +8,8 @@ module EventMachine
8
8
  class PubSubHubbub
9
9
  include EventMachine::Deferrable
10
10
 
11
+ HEADERS = {"User-Agent" => "PubSubHubbub Ruby", "Content-Type" => "application/x-www-form-urlencoded"}
12
+
11
13
  def initialize(hub)
12
14
  @hub = hub.kind_of?(URI) ? hub : URI::parse(hub)
13
15
  end
@@ -17,7 +19,7 @@ module EventMachine
17
19
  {'hub.url' => feed, 'hub.mode' => 'publish'}.to_params
18
20
  end.join("&")
19
21
 
20
- r = EventMachine::HttpRequest.new(@hub).post :body => data
22
+ r = EventMachine::HttpRequest.new(@hub).post :body => data, :head => HEADERS
21
23
  r.callback {
22
24
  if r.response_header.status == 204
23
25
  succeed r
@@ -30,52 +32,29 @@ module EventMachine
30
32
  r
31
33
  end
32
34
 
33
- ##
34
- # This will work only if ythe callback URL supports confirmation.
35
- def subscribe(feed, callback, options = {})
36
- options['hub.verify'] ||= "sync"
37
-
38
- params = {'hub.topic' => feed, 'hub.mode' => 'subscribe', 'hub.callback' => callback}.merge(options).to_params
35
+ # These command will work only if the callback URL supports confirmation.
36
+ def subscribe(feed, callback, options = {}); command('subscribe', feed, callback, options); end
37
+ def unsubscribe(feed, callback, options = {}); command('unsubscribe', feed, callback, options); end
39
38
 
40
- r = EventMachine::HttpRequest.new(@hub).post :body => params, :head => {"User-Agent" => "PubSubHubbub Ruby", "Content-Type" => "application/x-www-form-urlencoded", "Content-Length" => params.size }
41
-
42
- r.callback {
43
- if r.response_header.status == 204
44
- succeed r
45
- else
46
- fail r
47
- end
48
- }
49
-
50
- r.errback {
51
- fail
52
- }
53
- r
54
- end
39
+ private
55
40
 
56
- ##
57
- # This will work only if ythe callback URL supports confirmation.
58
- def unsubscribe(feed, callback, options = {})
41
+ def command(cmd, feed, callback, options)
59
42
  options['hub.verify'] ||= "sync"
60
-
61
- params = {'hub.topic' => feed, 'hub.mode' => 'unsubscribe', 'hub.callback' => callback}.merge(options).to_params
62
-
63
- r = EventMachine::HttpRequest.new(@hub).post :body => params, :head => {"User-Agent" => "PubSubHubbub Ruby", "Content-Type" => "application/x-www-form-urlencoded", "Content-Length" => params.size }
64
-
65
- r.callback {
43
+
44
+ params = {'hub.topic' => feed, 'hub.mode' => cmd, 'hub.callback' => callback}.merge(options).to_params
45
+ r = EventMachine::HttpRequest.new(@hub).post :body => params, :head => HEADERS
46
+
47
+ r.callback {
66
48
  if r.response_header.status == 204
67
49
  succeed r
68
50
  else
69
51
  fail r
70
52
  end
71
53
  }
72
-
73
- r.errback {
74
- fail
75
- }
54
+
55
+ r.errback { fail }
76
56
  r
77
57
  end
78
-
79
- end
80
- end
81
58
 
59
+ end
60
+ end
data/pubsubhubbub.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  spec = Gem::Specification.new do |s|
2
2
  s.name = 'pubsubhubbub'
3
- s.version = '0.1'
3
+ s.version = '0.1.1'
4
4
  s.date = '2009-06-28'
5
5
  s.summary = 'Ruby / Asynchronous PubSubHubbub Client'
6
6
  s.description = s.summary
@@ -9,7 +9,7 @@ spec = Gem::Specification.new do |s|
9
9
  s.has_rdoc = true
10
10
  s.authors = ["Ilya Grigorik"]
11
11
  s.add_dependency('eventmachine', '>= 0.12.2')
12
- s.add_dependency('em-http-request', '>= 0.1.6')
12
+ s.add_dependency('julien51-em-http-request', '>= 0.1.10')
13
13
  s.rubyforge_project = "pubsubhubbub"
14
14
 
15
15
  # ruby -rpp -e' pp `git ls-files`.split("\n") '
data/test/test_client.rb CHANGED
@@ -14,7 +14,7 @@ describe EventMachine::PubSubHubbub do
14
14
  EventMachine.run {
15
15
  pub = EventMachine::PubSubHubbub.new('http://pubsubhubbub.appspot.com/publish').publish "http://www.test.com/"
16
16
 
17
- pub.errback { fail }
17
+ pub.errback { failed }
18
18
  pub.callback {
19
19
  pub.response_header.status.should == 204
20
20
  EventMachine.stop
@@ -27,7 +27,7 @@ describe EventMachine::PubSubHubbub do
27
27
  feeds = ['http://www.test.com', 'http://www.test.com/2']
28
28
  pub = EventMachine::PubSubHubbub.new('http://pubsubhubbub.appspot.com/publish').publish feeds
29
29
 
30
- pub.errback { fail }
30
+ pub.errback { failed }
31
31
  pub.callback {
32
32
  pub.response_header.status.should == 204
33
33
  EventMachine.stop
@@ -39,7 +39,7 @@ describe EventMachine::PubSubHubbub do
39
39
  EventMachine.run {
40
40
  sub = EventMachine::PubSubHubbub.new('http://pubsubhubbub.appspot.com/').subscribe "http://blog.superfeedr.com/atom.xml", "http://superfeedr.com/hubbub", {}
41
41
 
42
- sub.errback { fail }
42
+ sub.errback { failed }
43
43
  sub.callback {
44
44
  sub.response_header.status.should == 204
45
45
  EventMachine.stop
@@ -51,7 +51,7 @@ describe EventMachine::PubSubHubbub do
51
51
  EventMachine.run {
52
52
  sub = EventMachine::PubSubHubbub.new('http://pubsubhubbub.appspot.com/').unsubscribe "http://blog.superfeedr.com/atom.xml", "http://superfeedr.com/hubbub", {}
53
53
 
54
- sub.errback { fail }
54
+ sub.errback { failed }
55
55
  sub.callback {
56
56
  sub.response_header.status.should == 204
57
57
  EventMachine.stop
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: julien51-pubsubhubbub
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.1"
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ilya Grigorik
@@ -23,14 +23,14 @@ dependencies:
23
23
  version: 0.12.2
24
24
  version:
25
25
  - !ruby/object:Gem::Dependency
26
- name: em-http-request
26
+ name: julien51-em-http-request
27
27
  type: :runtime
28
28
  version_requirement:
29
29
  version_requirements: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.1.6
33
+ version: 0.1.10
34
34
  version:
35
35
  description: Ruby / Asynchronous PubSubHubbub Client
36
36
  email: ilya@igvita.com