forked from mrmemes-eth/tomatoist
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ding.rb
65 lines (55 loc) · 1.39 KB
/
ding.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
require 'rubygems'
require 'sinatra/base'
require 'haml'
require 'environment'
class Ding < Sinatra::Default
enable :raise_errors
helpers do
def root_path
"/"
end
def session_path(session)
"/#{session.display_name}"
end
def session_timers_path(session)
"#{session_path(session)}/timers"
end
def timer
return nil unless @session
@timer ||= @session.last_timer
end
def next_timer
@next_timer ||= @session.next_timer
end
def new_timer_class(session,type)
session.next_timer == type ? 'next' : nil
end
end
get '/' do
redirect session_path(Session.create)
end
get '/faq' do
haml(:faq, :layout => false)
end
get '/:session/?' do
@session = Session.retrieve(params[:session])
redirect root_path unless @session
haml :timers
end
get '/:session/status.js/?' do
session = Session.retrieve(params[:session])
if session && (timer = session.last_timer)
{:expired => timer.expired?}.to_json
end
end
put '/:session' do
session = Session.retrieve(params[:session])
session.update_attributes(:custom => params[:custom])
redirect session_path(session.reload)
end
post '/:session/timers' do
session = Session.retrieve(params[:session])
session.timers.create(:type => params[:type], :offset => params[:offset])
redirect session_path(session)
end
end