Class: EventMachine::PubSubHubbub
- Inherits:
-
Object
- Object
- EventMachine::PubSubHubbub
- Includes:
- Deferrable
- Defined in:
- lib/pubsubhubbub/client.rb
Constant Summary collapse
- HEADERS =
{"User-Agent" => "PubSubHubbub Ruby", "Content-Type" => "application/x-www-form-urlencoded"}
Instance Method Summary collapse
-
#initialize(hub) ⇒ PubSubHubbub
constructor
A new instance of PubSubHubbub.
- #publish(*feeds) ⇒ Object
-
#subscribe(feed, callback, options = {}) ⇒ Object
These command will work only if the callback URL supports confirmation.
- #unsubscribe(feed, callback, options = {}) ⇒ Object
Constructor Details
#initialize(hub) ⇒ PubSubHubbub
Returns a new instance of PubSubHubbub.
13 14 15 |
# File 'lib/pubsubhubbub/client.rb', line 13 def initialize(hub) @hub = hub.kind_of?(URI) ? hub : URI::parse(hub) end |
Instance Method Details
#publish(*feeds) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/pubsubhubbub/client.rb', line 17 def publish(*feeds) data = feeds.flatten.collect do |feed| {'hub.url' => feed, 'hub.mode' => 'publish'}.to_params end.join("&") r = EventMachine::HttpRequest.new(@hub).post :body => data, :head => HEADERS r.callback { if r.response_header.status == 204 succeed r else fail r end } r.errback { fail } r end |
#subscribe(feed, callback, options = {}) ⇒ Object
These command will work only if the callback URL supports confirmation.
36 |
# File 'lib/pubsubhubbub/client.rb', line 36 def subscribe(feed, callback, = {}); command('subscribe', feed, callback, ); end |
#unsubscribe(feed, callback, options = {}) ⇒ Object
37 |
# File 'lib/pubsubhubbub/client.rb', line 37 def unsubscribe(feed, callback, = {}); command('unsubscribe', feed, callback, ); end |