-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathapi_v1.rb
More file actions
71 lines (66 loc) · 1.84 KB
/
Copy pathapi_v1.rb
File metadata and controls
71 lines (66 loc) · 1.84 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
class TempestWatch < Sinatra::Base
namespace '/api/v1' 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
status 200
tempests = {}
current_tempests.each do |map, tempest|
tempests[map] = {
name: tempest.name,
base: tempest.base_name,
suffix: tempest.suffix_name,
votes: tempest.votes,
type: tempest.type
}
end
body 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({
name: map.tempest.name,
base: map.tempest.base_name,
suffix: map.tempest.suffix_name,
votes: map.tempest.votes,
type: map.tempest.type
}.to_json)
end
end
end
end