Class: EventMachine::PubSubHubbub

Inherits:
Object
  • Object
show all
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

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, options = {});   command('subscribe', feed, callback, options);   end

#unsubscribe(feed, callback, options = {}) ⇒ Object



37
# File 'lib/pubsubhubbub/client.rb', line 37

def unsubscribe(feed, callback, options = {}); command('unsubscribe', feed, callback, options); end