Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions lib/stream_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
# uses twich api to get mos live streams
class StreamFinder
def self.fetch_streams
url = 'https://api.twitch.tv/kraken/streams/'
url = 'https://api.twitch.tv/helix/streams/'
options = {
headers: {
'Client-ID' => Settings.twitch_api['client_id']
},
format: :plain,
query: { game: 'Marbles On Stream' }
query: { game_id: '509511' }
}

data = HTTParty.get(url, options)
Expand All @@ -18,8 +18,8 @@ def self.fetch_streams

def self.parse_stream(stream)
{
stream[:channel][:name] => {
viewers: stream[:viewers],
stream[:user_name] => {
viewers: stream[:viewer_count],
updated_at: Time.now
}
}
Expand All @@ -28,10 +28,10 @@ def self.parse_stream(stream)
def self.parse_streams(streams, min_viewers, max_channels)
channels = {}

if streams[:_total] > 0
streams[:streams].each do |stream|
if streams[:data].count > 0
streams[:data].each do |stream|
break if channels.size >= max_channels
next if stream[:viewers] < min_viewers
next if stream[:viewer_count] < min_viewers

channels.merge! parse_stream(stream)
end
Expand Down