-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
67 lines (47 loc) · 1.09 KB
/
app.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
64
65
66
67
require 'pusher'
require 'sinatra'
require 'sinatra/cross_origin'
configure do
enable :cross_origin
end
before do
response.headers['Access-Control-Allow-Origin'] = '*'
end
options '*' do
response.headers['Allow'] = 'GET, POST, OPTIONS'
response.headers['Access-Control-Allow-Headers'] = 'Authorization, Content-Type, Accept, X-User-Email, X-Auth-Token'
response.headers['Access-Control-Allow-Origin'] = '*'
200
end
post '/api/buzz' do
pusher.trigger('buzzes', 'player-buzzed', name: data['name'])
200
end
post '/api/reset' do
pusher.trigger('buzzes', 'admin-reseted', name: data['name'])
200
end
post '/api/reset_all' do
pusher.trigger('buzzes', 'admin-reseted-all', {})
200
end
post '/api/right' do
pusher.trigger('buzzes', 'admin-accepted', name: data['name'])
200
end
post '/api/wrong' do
pusher.trigger('buzzes', 'admin-rejected', name: data['name'])
200
end
def data
@_data ||= JSON.parse(request.body.read)
end
def pusher
Pusher::Client.new({
app_id: 'OSEF',
key: 'buzzouce',
secret: 'endive',
host: '0.0.0.0',
port: 4567
})
end