Class: Hootenanny::TopicSynchronizer

Inherits:
Object
  • Object
show all
Defined in:
lib/hootenanny/topic_synchronizer.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ TopicSynchronizer

Returns a new instance of TopicSynchronizer.



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/hootenanny/topic_synchronizer.rb', line 5

def initialize(options = {})
  self.subscriber_url        = options.fetch(:subscriber)
  self.topic_url             = options.fetch(:topic)
  self.digest_secret         = options.fetch(:digest_secret, nil)

  self.local_feed_store      = options[:local_feed_store] ||
                               Hootenanny.config.default_local_feed_store
  self.remote_feed_store     = options[:remote_feed_store] ||
                               Hootenanny.config.default_remote_feed_store
  self.subscription_delivery = options[:subscription_delivery] ||
                               Hootenanny.config.default_subscription_delivery
end

Class Method Details

.sync(options = {}) ⇒ Object



18
19
20
# File 'lib/hootenanny/topic_synchronizer.rb', line 18

def self.sync(options = {})
  self.new(options).sync
end

Instance Method Details

#syncObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/hootenanny/topic_synchronizer.rb', line 22

def sync
  return true if unsynchronized_feed.empty?

  if subscription_delivery.deliver( feed:       unsynchronized_feed,
                                    url:        topic_url,
                                    subscriber: subscriber_url)

    local_feed_store.store( feed:  remote_feed.to_digest_feed,
                            url:   topic_url,
                            type:  'digest',
                            path:  subscriber_url.to_digest)
  else
    false
  end
end