-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscoreboard.rb
More file actions
76 lines (57 loc) · 1.28 KB
/
scoreboard.rb
File metadata and controls
76 lines (57 loc) · 1.28 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env ruby
require 'dotenv'
Dotenv.load
require 'json'
require 'sinatra/base'
require 'pusher'
require 'redis'
require 'redis-objects'
require 'connection_pool'
redis_url = ENV['REDIS_URL']
Redis::Objects.redis = ConnectionPool.new(size: 5, timeout: 5) { Redis.new(url: redis_url) }
require './lib/match'
require './lib/player'
Pusher.url = "http://#{ENV['PUSHER_KEY']}:#{ENV['PUSHER_SECRET']}@api.pusherapp.com/apps/#{ENV['PUSHER_APP']}"
class Scoreboard < Sinatra::Base
get '/' do
erb :index, locals: { scores: match.scores }
end
post '/new_game' do
@match = Match.new(params[:one], params[:two])
@match.reset_scores
@match.reset_games
push_scores
JSON match.scores
end
put '/reset_scores' do
match.reset_scores
match.reset_games
push_scores
end
put '/red_scores' do
match.add_point(:red)
push_scores
end
put '/blue_scores' do
match.add_point(:blue)
push_scores
end
put '/red_undo' do
match.undo_point(:red)
push_scores
end
put '/blue_undo' do
match.undo_point(:blue)
push_scores
end
get '/scores' do
JSON match.scores
end
def push_scores
Pusher['scores'].trigger('update_scores', match.scores.to_json)
end
private
def match
@match ||= Match.new
end
end