Class: StreamBot::Tracker

Inherits:
Object
  • Object
show all
Extended by:
EventHandler
Defined in:
lib/streambot/tracker.rb

Overview

The Tracker class that provides a start and a stop method This class has serveral callback methods

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from EventHandler

event, events

Constructor Details

#initialize(params) ⇒ Tracker

initializes the tracker



11
12
13
14
15
16
17
18
19
# File 'lib/streambot/tracker.rb', line 11

def initialize(params)
  self.params = params
  @retweet = StreamBot::Retweet.new(self.params)
  @client = TwiStream::Client.new(authentication)
  @client.on_error.handle do |msg, trace|
    LOG.error "#{msg}"
    on_error.trigger(msg, trace)
  end
end

Instance Attribute Details

#authObject

Returns the value of attribute auth.



8
9
10
# File 'lib/streambot/tracker.rb', line 8

def auth
  @auth
end

#paramsObject

Returns the value of attribute params.



8
9
10
# File 'lib/streambot/tracker.rb', line 8

def params
  @params
end

Instance Method Details

#startObject

start the tracker



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/streambot/tracker.rb', line 22

def start
  keywords = self.params["keywords"]
  @thread = Thread.new do 
    @client.filter_by_keywords(keywords) do |status|
      if retweet?(status)
        before_retweet.trigger(status)
        @retweet.retweet(status["id"])
        after_retweet.trigger(status)
      end
    end
  end
  @thread.join
end

#stopObject

stop the tracker



37
38
39
# File 'lib/streambot/tracker.rb', line 37

def stop
  @client.stop
end