-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathapi_v0.rb
More file actions
54 lines (49 loc) · 1.38 KB
/
Copy pathapi_v0.rb
File metadata and controls
54 lines (49 loc) · 1.38 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
class TempestWatch < Sinatra::Base
namespace '/api/v0' do
post '/vote' do
map = Map.get(params[:map])
if map.nil?
status 400
body "Map #{params[:map]} does not exist"
elsif Tempest::BASES[params[:base]].nil?
status 400
body "Tempest #{params[:base]} does not exist"
elsif params[:suffix] && Tempest::SUFFIXES[params[:suffix]].nil?
status 400
body "Suffix #{params[:suffix]} does not exist"
else
skip_validation = params[:api_key] && ($redis.exists "apikey::#{params[:api_key]}")
if params[:api_key] && !skip_validation
status 400
body "Invalid api key: #{params[:api_key]}"
return
end
tempest = Tempest.new(params[:base], params[:suffix])
map.report_tempest(tempest, request.ip, seconds_to_reset, skip_validation)
200
end
end
get '/tempests' do
return {
bases: Tempest::BASES,
suffixes: Tempest::SUFFIXES
}.to_json
end
get '/maps' do
Map::LEVELS.to_json
end
get '/current_tempests' do
return current_tempests.to_json
end
get '/current_tempests/:map' do
map = Map.get(params[:map])
if map.nil?
status 400
body "Map #{params[:map]} does not exist"
else
status 200
body map.tempest.to_json
end
end
end
end