Class: Atig::Agent::StreamFollow

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/atig/agent/stream_follow.rb

Instance Method Summary collapse

Methods included from ExceptionUtil

daemon, safe

Constructor Details

#initialize(context, api, db) ⇒ StreamFollow

Returns a new instance of StreamFollow.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/atig/agent/stream_follow.rb', line 9

def initialize(context, api, db)
  @log = context.log
  @api = api
  @prev = nil

  return unless context.opts.stream

  log :info, "initialize"

  @api.delay(0)do|t|
    @follows = context.opts.follow.split(',').map{|user|
      t.get("users/show",:screen_name=>user).id
    }.join(',')
  end


  @api.stream do|t|
    Thread.pass until @follows
    t.watch('statuses/filter', :follow => @follows) do |status|
      if status and status.user
        db.transaction do|d|
          d.statuses.add :status => status, :user => status.user, :source => :stream_follow
        end
      end
    end
  end
end