-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.rb
94 lines (73 loc) · 2.21 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
require 'sinatra'
require 'sinatra/namespace'
require 'json'
require_relative 'utils/github'
require_relative 'utils/couchdb'
require_relative 'transformer/hackathon'
require_relative 'transformer/leaderboard'
require_relative 'target/panic'
# Hackatus for Hackathon
namespace '/hackathon' do
get '/chart.json' do
title, obj = parse_params params
# Set file typ eo application/json
response.headers["Content-Type"] = "application/json"
# generates data
hackathon = Hackathon.new title, obj
hackathon.chart.to_json
end
get '/table.html' do
title, obj = parse_params params {|is_hackathon| 2 if is_hackathon }
hackathon = Hackathon.new title, obj
hackathon.table(open("template/hackathon_table.html.erb").read)
end
get '/table.json' do
title, obj = parse_params params {|is_hackathon| 2 if is_hackathon }
hackathon = Hackathon.new title, obj
hackathon.table.to_json
end
private
def parse_params params
hackathon = false
obj = {}
title = ""
case params["type"]
when "explore"
period = params["period"]
period = "day" unless Github.valid_period? period
obj["repos"] = Github.explore period
title = "Trending of the #{period.capitalize}"
else
obj = JSON.load(open('config.json').read)
title = "Hackathon Status"
hackathon = true;
end
since = yield(hackathon) if block_given?
since ||= 24 # default to 24 hours
obj["since"] ||= since.hours_ago # default to 24 hours ago
[title, obj]
end
end
# Hackatus for Leaderboard
namespace '/leaderboard' do
get '/chart.json' do
# Set file typ eo application/json
response.headers["Content-Type"] = "application/json"
title = "Screek Leaderboard"
obj = CouchDB.score_board
leaderboard = Leaderboard.new title, obj
leaderboard.chart.to_json
end
get '/table.html' do
title = "Screek Leaderboard"
obj = CouchDB.activity_history
hackathon = Leaderboard.new title, obj
hackathon.table(open("template/leaderboard_table.html.erb").read)
end
get '/table.json' do
title = "Screek Leaderboard"
obj = CouchDB.activity_history
hackathon = Leaderboard.new title, obj
hackathon.table.to_json
end
end