Class: Twitchus::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/twitchus/worker.rb

Instance Method Summary collapse

Constructor Details

#initialize(config_file) ⇒ Worker

Returns a new instance of Worker.



4
5
6
7
8
# File 'lib/twitchus/worker.rb', line 4

def initialize(config_file)
  @config = Twitchus::Config.new
  @config.load(config_file)
  @checker = Twitchus::Checker.new(@config)
end

Instance Method Details

#runObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/twitchus/worker.rb', line 10

def run
  @storage = Twitchus::Storage.new(@config.host, @config.port, @config.key)
  # Since this can run periodically, clean the list first
  @storage.clear

  online_streams = @checker.fetch_all(@config.streams)
  online_streams.each do |data|
    channel = data["channel"]
    data = {
      title:   channel["status"],
      name:    channel["name"],
      image:   channel["video_banner"],
      preview: data["preview"]
    }

    @storage.push data.to_json
  end
end