-
Notifications
You must be signed in to change notification settings - Fork 4
/
README
156 lines (108 loc) · 5.25 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
WebGlue
========
PubSubHubbub Ruby implementation
Overview
---------
PubSubHubbub (PSHB) is a simple, open, server-to-server web-hook-based pubsub
(publish/subscribe) protocol as an extension to Atom. For more details see
http://code.google.com/p/pubsubhubbub/ .
Current project is as simple as possible implementation in Ruby of PSHB Core 0.2
Draft-compatible hub.
Implemented features:
- Publishing new topics (Atom Feeds)
- Subscriptions to existing topics (including callbacks verification) - 'sync' and
'async' mode verifications
- Fetching atom feeds, finding the new entries and sending them to all subscribers
- Authenticated Content Distribution - 'hub.secret'
Still missing (not implemented):
- Publishers need to manually ping the hub (no automatic check for updated feeds)
- Can only process Atom feeds, not RSS
Required gems
--------------
- sinatra - web framework - routing etc.
- httpclient - POST requests, callbacks verification
- crack - XML parsing
- ratom - Atom feeds fetching/parsing
- SystemTimer - for timeouts on unsuccessful requests
- ruby-hmac - HMAC-SHA1 for content digests
If you are using http://heroku.com/ for deployment, your '.gems' file will look like:
httpclient
SystemTimer
crack
ratom
ruby-hmac
Running
------
The whole system is implemented as a Sinatra [ http://www.sinatrarb.com/ ] application.
To start it locally (on port 4567 for example):
git clone git://github.com/zh/webglue.git
cd webglue
bundle install
bundle exec rackup -p 4567 -s thin
For production environment, maybe using 'unicorn' is better:
bundle exec unicorn -c ./unicorn.conf -E production
(optional)
'async' verification worker process:
- from crontab:
require 'worker'
WebGlue::Worker.verify
- independent daemon (checks every WebGlue::Config.CHECK minutes)
require 'worker'
WebGlue::Worker.run
Or you can uncomment the proper lines in worker.rb ('if __FILE__ == $0' block) and do
ruby worker.rb
http://heroku.com/ will automatically recognize the startup file (config.ru) and will
run your application after the deployment:
git clone git://github.com/zh/webglue.git
cd webglue
heroku create mypubhub
git push heroku master
PubSub
-------
Both publishing and subscriptions going to the same endpoint - '/'. So if your application
is running on URL http://localhost:4567/ , that will be the endpoint for both publishers
(atom:link[@rel="hub"] in the feed) and subscribers (POST requests for subscription).
Only for debugging purposes, there are two web form on '/publish' and '/subscribe' URLs.
Publishing new topics
----------------------
If your application is running on URL http://localhost:4567/ , go to
http://localhost:4567/publish and insert your Atom feed in the 'Topic:' text box. Press
"Publish". There will be no changes on the screen, because the hub is responding with
HTTP code 204 "No Content".
You can also POST directly to http://localhost:4567/ with parameters, described
in the "PubSubHubbub Core 0.2" document -
http://pubsubhubbub.googlecode.com/svn/trunk/pubsubhubbub-core-0.2.html
Also in your feed, insert the line:
<link rel="hub" href="http://localhost:4567/" /> (adjust for your install)
For now, there is no automatic check for updated feeds implemented, so after changes in
some feed, repeat the actions, described above (from the web form or via POST).
Publishing is possible once every 5 min.
Subscription to existing topics
--------------------------------
If your application is running on URL http://localhost:4567/ , go to
http://localhost:4567/subscribe and fill the web form:
- Callback - URL to the webhook, which will receive Atom-formated notifications
- Topic - Atom feed URL, ALREADY PUBLISHED to the system - see 'Publishing new topics'
above
- Verify mode - Both 'Synchronous' and 'Asynchronous' modes supported
- Mode - 'Subscribe' for adding new subscribers and 'Unsubscribe' for removing
the already inserted onces
- Verify token - something that your callback need to approve
- Secret - used to compute an HMAC digest of the content, send to the subscriber
You can send also POST subscription requests with the required parameters directly to
the hub endpoint (http://localhost:4567/ in our example).
The hub is implementing callbacks verification, described in the "PubSubHubbub Core 0.2"
document (sending back 'hub.challenge' parameter in the response body).
In 'Synchronous' mode there will be no changes on the screen after subscription,
because the hub is responding with HTTP code 204 "No Content".
In 'Asynchronous' mode the hub will respond with HTTP code 202 "Scheduled for verification"
Notifications format
---------------------
Current implementation fetch the Atom feeds and just remove already known entries from
them, without touching other parts of the feed ('title', 'id', 'author' etc.).
After that, the feed, with only new entries in it is resend to all topic's subscribers.
Because of that, the hub cannot process RSS feeds and may have some problems with
non-well formated feeds. I'll try to fix this in the future releases.
If the subscriber supplied a value for 'hub.secret' in their subscription request,
the hub will generate an HMAC signature of the payload and include that signature in
the response headers ('X-Hub-Signature') of the notification.