Class: Lotus::Publisher

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ 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
22
23
24
25
26
27
# File 'lib/lotus/publisher.rb', line 19

def initialize(options = {})
  if options[:feed]
    @url  = options[:feed].url
    @hubs = options[:feed].hubs
  end

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

Instance Attribute Details

#hubsObject (readonly)

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



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

def hubs
  @hubs
end

#urlObject (readonly)

The url of the feed.



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

def url
  @url
end

Instance Method Details

#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.



32
33
34
35
36
37
38
# File 'lib/lotus/publisher.rb', line 32

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