Class: TwittyConsole::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/twitty-console/runner.rb

Class Method Summary collapse

Class Method Details

.runObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/twitty-console/runner.rb', line 17

def self.run
  TwittyConsole::Config.setup

  rate = TwittyConsole::Account.rate_limit_status
  interval = 3600 / rate

  cui = TwittyConsole::CUI.new
  cui.handler = TwittyConsole::PostHandler.new

  Signal.trap(:INT, "EXIT")

  threads = []
  threads << Thread.start do
    loop do
      begin
        statuses = TwittyConsole::Status.friends_timeline
        cui.output statuses unless statuses.empty?
      rescue
        cui.warn $!.message
      end
      sleep interval
    end
  end
  threads << Thread.start do
    cui.start
  end
  threads.each do |t|
    t.join
  end
ensure
  cui.stop if cui
end