-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.rb
63 lines (51 loc) · 1.58 KB
/
server.rb
1
2
3
4
5
6
7
8
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
module Karnak
class Server < Sinatra::Base
configure :development do
require 'pry'
register Sinatra::Reloader
# $db = Redis.new
end
enable :sessions
register Sinatra::Flash
get '/' do
# top_games_url = "https://api.twitch.tv/kraken/games/top?limit=12"
# top_games_hash = HTTParty.get top_games_url
# @top_games = top_games_hash["top"]
erb :index
end
get '/games/:name' do
# get network feeds
@game = params[:name]
@twitch_streams = TwitchHelper.streams @game
@hitbox_streams = HitboxHelper.streams @game
if @twitch_streams.has_key? "error" #twitch gives you back a hash on error
flash.now[:error] = "Twitch may be having issues at the moment. #{ @twitch_streams }"
@twitch_streams = [] # this makes the stream merge below work
end
# merge all network feeds
@streams = @twitch_streams | @hitbox_streams
limit = params[:limit] || 24
offset = params[:start] || 0
@streams = @streams[(offset.to_i)..-1].take(limit.to_i)
erb :games
end
post '/games' do
query = URI.escape(params[:game])
redirect "/games/#{query}"
end
get '/about' do
erb :about
end
get '/stream/twitch/:id' do
@stream = TwitchHelper.get_stream(params[:id])
if @stream.has_key? 'error'
flash.now[:error] = "Error from Twitch: \n #{ @stream }"
end
erb :stream
end
get '/stream/hitbox/:id' do
@stream = HitboxHelper.get_stream(params[:id])
erb :stream
end
end#Server
end#Karnak