Class: Atig::Agent::Dm

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

Instance Method Summary collapse

Methods included from ExceptionUtil

daemon, safe

Constructor Details

#initialize(context, api, db) ⇒ Dm

Returns a new instance of Dm.



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
# File 'lib/atig/agent/dm.rb', line 9

def initialize(context, api, db)
  return if context.opts.stream
  @log = context.log
  @api = api
  @prev = nil

  log :info, "initialize"

  @api.repeat(600) do|t|
    q = { :count => 200 }
    if @prev
      q.update :since_id => @prev
    else
      q.update :count => 1
    end
    dms = t.get("direct_messages", q)
    log :debug, "You have #{dms.size} dm."

    dms.reverse_each do|dm|
      db.dms.transaction do|d|
        d.add :status => dm, :user => dm.sender
      end
    end
  end
end