julien51-pubsubhubbub 0.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.
- data/README.rdoc +27 -0
- data/lib/pubsubhubbub/client.rb +81 -0
- data/lib/pubsubhubbub.rb +10 -0
- data/pubsubhubbub.gemspec +21 -0
- data/test/test_client.rb +62 -0
- metadata +77 -0
data/README.rdoc
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
= Ruby / Asynchronous PubSubHubbub Client
|
2
|
+
|
3
|
+
EventMachine based / asynchronous PubSubHubbub client. Supports posting single or multiple URLs.
|
4
|
+
|
5
|
+
Full Spec: http://code.google.com/p/pubsubhubbub
|
6
|
+
|
7
|
+
HTTP PubSub: Webhooks & PubSubHubbub: http://www.igvita.com/2009/06/29/http-pubsub-webhooks-pubsubhubbub
|
8
|
+
|
9
|
+
== Simple client example
|
10
|
+
|
11
|
+
EventMachine.run {
|
12
|
+
pub = EventMachine::PubSubHubbub.new('http://pubsubhubbub.appspot.com/publish').publish "http://www.test.com/"
|
13
|
+
|
14
|
+
pub.callback { puts "Successfully notified hub." }
|
15
|
+
pub.errback { puts "Uh oh, something broke: #{pub.response}" }
|
16
|
+
}
|
17
|
+
|
18
|
+
== Posting multiple URL's
|
19
|
+
|
20
|
+
EventMachine.run {
|
21
|
+
feeds = ["http://www.test.com", "http://www.test.com/2"]
|
22
|
+
pub = EventMachine::PubSubHubbub.new('http://pubsubhubbub.appspot.com/publish').publish feeds
|
23
|
+
|
24
|
+
pub.callback { puts "Successfully notified hub." }
|
25
|
+
pub.errback { puts "Uh oh, something broke: #{pub.response}" }
|
26
|
+
}
|
27
|
+
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# #--
|
2
|
+
# Copyright (C)2009 Ilya Grigorik
|
3
|
+
#
|
4
|
+
# You can redistribute this under the terms of the Ruby
|
5
|
+
# #--
|
6
|
+
|
7
|
+
module EventMachine
|
8
|
+
class PubSubHubbub
|
9
|
+
include EventMachine::Deferrable
|
10
|
+
|
11
|
+
def initialize(hub)
|
12
|
+
@hub = hub.kind_of?(URI) ? hub : URI::parse(hub)
|
13
|
+
end
|
14
|
+
|
15
|
+
def publish(*feeds)
|
16
|
+
data = feeds.flatten.collect do |feed|
|
17
|
+
{'hub.url' => feed, 'hub.mode' => 'publish'}.to_params
|
18
|
+
end.join("&")
|
19
|
+
|
20
|
+
r = EventMachine::HttpRequest.new(@hub).post :body => data
|
21
|
+
r.callback {
|
22
|
+
if r.response_header.status == 204
|
23
|
+
succeed r
|
24
|
+
else
|
25
|
+
fail r
|
26
|
+
end
|
27
|
+
}
|
28
|
+
|
29
|
+
r.errback { fail }
|
30
|
+
r
|
31
|
+
end
|
32
|
+
|
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
|
39
|
+
|
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
|
55
|
+
|
56
|
+
##
|
57
|
+
# This will work only if ythe callback URL supports confirmation.
|
58
|
+
def unsubscribe(feed, callback, options = {})
|
59
|
+
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 {
|
66
|
+
if r.response_header.status == 204
|
67
|
+
succeed r
|
68
|
+
else
|
69
|
+
fail r
|
70
|
+
end
|
71
|
+
}
|
72
|
+
|
73
|
+
r.errback {
|
74
|
+
fail
|
75
|
+
}
|
76
|
+
r
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
data/lib/pubsubhubbub.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
spec = Gem::Specification.new do |s|
|
2
|
+
s.name = 'pubsubhubbub'
|
3
|
+
s.version = '0.1'
|
4
|
+
s.date = '2009-06-28'
|
5
|
+
s.summary = 'Ruby / Asynchronous PubSubHubbub Client'
|
6
|
+
s.description = s.summary
|
7
|
+
s.email = 'ilya@igvita.com'
|
8
|
+
s.homepage = "http://github.com/igrigorik/pubsubhubbub"
|
9
|
+
s.has_rdoc = true
|
10
|
+
s.authors = ["Ilya Grigorik"]
|
11
|
+
s.add_dependency('eventmachine', '>= 0.12.2')
|
12
|
+
s.add_dependency('em-http-request', '>= 0.1.6')
|
13
|
+
s.rubyforge_project = "pubsubhubbub"
|
14
|
+
|
15
|
+
# ruby -rpp -e' pp `git ls-files`.split("\n") '
|
16
|
+
s.files = ["README.rdoc",
|
17
|
+
"lib/pubsubhubbub.rb",
|
18
|
+
"lib/pubsubhubbub/client.rb",
|
19
|
+
"pubsubhubbub.gemspec",
|
20
|
+
"test/test_client.rb"]
|
21
|
+
end
|
data/test/test_client.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'spec'
|
3
|
+
require 'eventmachine'
|
4
|
+
require 'lib/pubsubhubbub'
|
5
|
+
|
6
|
+
describe EventMachine::PubSubHubbub do
|
7
|
+
|
8
|
+
def failed
|
9
|
+
EventMachine.stop
|
10
|
+
fail
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should publish single feed to hub" do
|
14
|
+
EventMachine.run {
|
15
|
+
pub = EventMachine::PubSubHubbub.new('http://pubsubhubbub.appspot.com/publish').publish "http://www.test.com/"
|
16
|
+
|
17
|
+
pub.errback { fail }
|
18
|
+
pub.callback {
|
19
|
+
pub.response_header.status.should == 204
|
20
|
+
EventMachine.stop
|
21
|
+
}
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should publish multiple feeds to hub" do
|
26
|
+
EventMachine.run {
|
27
|
+
feeds = ['http://www.test.com', 'http://www.test.com/2']
|
28
|
+
pub = EventMachine::PubSubHubbub.new('http://pubsubhubbub.appspot.com/publish').publish feeds
|
29
|
+
|
30
|
+
pub.errback { fail }
|
31
|
+
pub.callback {
|
32
|
+
pub.response_header.status.should == 204
|
33
|
+
EventMachine.stop
|
34
|
+
}
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should subscribe a single feed to hub" do
|
39
|
+
EventMachine.run {
|
40
|
+
sub = EventMachine::PubSubHubbub.new('http://pubsubhubbub.appspot.com/').subscribe "http://blog.superfeedr.com/atom.xml", "http://superfeedr.com/hubbub", {}
|
41
|
+
|
42
|
+
sub.errback { fail }
|
43
|
+
sub.callback {
|
44
|
+
sub.response_header.status.should == 204
|
45
|
+
EventMachine.stop
|
46
|
+
}
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should unsubscribe a single feed to hub" do
|
51
|
+
EventMachine.run {
|
52
|
+
sub = EventMachine::PubSubHubbub.new('http://pubsubhubbub.appspot.com/').unsubscribe "http://blog.superfeedr.com/atom.xml", "http://superfeedr.com/hubbub", {}
|
53
|
+
|
54
|
+
sub.errback { fail }
|
55
|
+
sub.callback {
|
56
|
+
sub.response_header.status.should == 204
|
57
|
+
EventMachine.stop
|
58
|
+
}
|
59
|
+
}
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: julien51-pubsubhubbub
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "0.1"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ilya Grigorik
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-06-28 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: eventmachine
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.12.2
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: em-http-request
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.1.6
|
34
|
+
version:
|
35
|
+
description: Ruby / Asynchronous PubSubHubbub Client
|
36
|
+
email: ilya@igvita.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files: []
|
42
|
+
|
43
|
+
files:
|
44
|
+
- README.rdoc
|
45
|
+
- lib/pubsubhubbub.rb
|
46
|
+
- lib/pubsubhubbub/client.rb
|
47
|
+
- pubsubhubbub.gemspec
|
48
|
+
- test/test_client.rb
|
49
|
+
has_rdoc: true
|
50
|
+
homepage: http://github.com/igrigorik/pubsubhubbub
|
51
|
+
licenses:
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: "0"
|
62
|
+
version:
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: "0"
|
68
|
+
version:
|
69
|
+
requirements: []
|
70
|
+
|
71
|
+
rubyforge_project: pubsubhubbub
|
72
|
+
rubygems_version: 1.3.5
|
73
|
+
signing_key:
|
74
|
+
specification_version: 2
|
75
|
+
summary: Ruby / Asynchronous PubSubHubbub Client
|
76
|
+
test_files: []
|
77
|
+
|