Sha256: 4a7ce90cc38e9ab5406d49055fe5426d20c84fa54467318e6bbc7ae86b240ab3

Contents?: true

Size: 1.03 KB

Versions: 3

Compression:

Stored size: 1.03 KB

Contents

require 'em-http'

module Weeter
  class Runner

    def initialize(config)
      @config = config
      Weeter.logger.info("Starting weeter with configuration: #{@config.inspect}")
    end

    def start
      EM.run {
        subscription_plugin.get_initial_filters do |filter_params|
          Weeter.logger.info("Connecting to twitter with initial filters")
          tweet_consumer.connect(filter_params)
          subscription_plugin.listen_for_filter_update(tweet_consumer)

          trap('TERM') do
            Weeter.logger.info("Stopping weeter")
            EM.stop if EM.reactor_running?
          end
        end
      }
    end

  protected
  
    def notification_plugin
      @notification_plugin ||= Weeter::Plugins::NotificationPlugin.new(@config.client_app)
    end

    def subscription_plugin
      @subscription_plugin ||= Weeter::Plugins::SubscriptionPlugin.new(@config.client_app)
    end

    def tweet_consumer
      @tweet_consumer ||= Weeter::Twitter::TweetConsumer.new(@config.twitter, notification_plugin)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
weeter-0.9.2 lib/weeter/runner.rb
weeter-0.9.1 lib/weeter/runner.rb
weeter-0.9.0 lib/weeter/runner.rb