Class: Nelumba::Publisher

Inherits:
Object
  • Object
show all
Defined in:
lib/nelumba/publisher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, &blk) ⇒ Publisher

Creates a representation of a Publisher entity.

options:

:feed => A feed to use to populate the other fields.
:url  => The url of the feed that will be published.
:hubs => An array of hub urls that are used to handle load
         balancing pushes of new data. Default: []


19
20
21
# File 'lib/nelumba/publisher.rb', line 19

def initialize(options = {}, &blk)
  init(options, &blk)
end

Instance Attribute Details

#hubsObject (readonly)

The array of feed urls used to push content. Default: []



10
11
12
# File 'lib/nelumba/publisher.rb', line 10

def hubs
  @hubs
end

#urlObject (readonly)

The url of the feed.



7
8
9
# File 'lib/nelumba/publisher.rb', line 7

def url
  @url
end

Instance Method Details

#init(options = {}, &blk) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/nelumba/publisher.rb', line 23

def init(options = {}, &blk)
  if options[:feed]
    @url  = options[:feed].url
    @hubs = options[:feed].hubs
  end

  @url  ||= options[:url]
  @hubs ||= options[:hubs] || []
end

#ping_hubsObject

Will ping PuSH hubs so that they know there is new/updated content. The hub should respond by pulling the new data and then sending it to subscribers.



36
37
38
39
40
41
42
# File 'lib/nelumba/publisher.rb', line 36

def ping_hubs
  @hubs.each do |hub_url|
    res = Net::HTTP.post_form(URI.parse(hub_url),
                              { 'hub.mode' => 'publish',
                                'hub.url' => @topic_url })
  end
end