Module: Seize

Defined in:
lib/seize/utils.rb,
lib/seize/twitch.rb,
lib/seize/version.rb,
lib/seize/commands.rb

Defined Under Namespace

Modules: Twitch, Utils

Constant Summary collapse

VERSION =
"1.0.2"

Class Method Summary collapse

Class Method Details

.check(channel_name) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/seize/commands.rb', line 43

def self.check(channel_name)
  channel = Seize::Twitch.get_channel(channel_name)
  if channel.nil?
    puts 'error: channel does not exist'
  elsif channel['stream'].nil?
    puts "#{channel_name} is offline"
  else
    game = channel['stream']['game']
    viewers = Seize::Utils.commaize(channel['stream']['viewers'])
    puts "#{channel_name} is playing #{game} with #{viewers} viewers"
  end
end

.list(number) ⇒ Object



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
36
37
38
39
40
41
# File 'lib/seize/commands.rb', line 11

def self.list(number)
  line_length = 79
  number_length = 5
  name_length = 20
  viewers_length = 12
  game_length = 40
  row_template = " %-#{number_length}{number}" \
                 " %-#{name_length}{name}" \
                 " %-#{viewers_length}{viewers}" \
                 " %{game}\n"
  result = ''
  line = '-' * line_length << "\n"
  result << line
  result << row_template % {
    :number => '#',
    :name => 'channel',
    :viewers => 'viewers',
    :game => 'game'
  } 
  result << line
  streams = Seize::Twitch.get_streams(limit: number)['streams']
  streams.each_with_index do |stream, i|
    result << row_template % {
      :number => "#{i+1}.",
      :name => Seize::Utils.truncate(stream['channel']['name'], name_length),
      :viewers => Seize::Utils.commaize(stream['viewers']),
      :game => Seize::Utils.truncate(stream['game'], game_length)
    }
  end
  puts result
end

.watch(channel, quality) ⇒ Object



7
8
9
# File 'lib/seize/commands.rb', line 7

def self.watch(channel, quality)
  exec("livestreamer https://twitch.tv/#{channel} #{quality}")
end