Class: EventMachine::PubSubHubbub

Inherits:
Object
  • Object
show all
Includes:
Deferrable, HttpEncoding
Defined in:
lib/pubsubhubbub/client.rb,
lib/pubsubhubbub/version.rb

Constant Summary collapse

HEADERS =
{"User-Agent" => "PubSubHubbub Ruby", "Content-Type" => "application/x-www-form-urlencoded"}
VERSION =
'0.2.0'

Instance Method Summary collapse

Constructor Details

#initialize(hub, options = {}) ⇒ PubSubHubbub

Returns a new instance of PubSubHubbub.



14
15
16
17
# File 'lib/pubsubhubbub/client.rb', line 14

def initialize(hub, options={})
  @headers = HEADERS.merge(options[:head]) if options[:head]
  @hub = hub.kind_of?(URI) ? hub : URI::parse(hub)
end

Instance Method Details

#publish(*feeds) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/pubsubhubbub/client.rb', line 19

def publish(*feeds)
  data = feeds.flatten.collect do |feed|
    form_encode_body({'hub.url' => feed, 'hub.mode' => 'publish'})
  end.join("&")

  request(:body => data, :head => @headers)
end

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

These command will work only if the callback URL supports confirmation.



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

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

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



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

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