-
Notifications
You must be signed in to change notification settings - Fork 12
/
app.rb
57 lines (48 loc) · 1014 Bytes
/
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
require 'sinatra'
require 'sinatra/content_for'
require './server'
require 'awesome_print'
set :bind, '127.0.0.1'
set :server, "thin"
# prevent conneciton leaks
after do
ActiveRecord::Base.connection.close
end
server = SlashNomServer.new
before do
if params['team_id'].present?
params['slack_bot_token'] = Team.get_slack_bot_token(params['team_id'])
end
end
post '/nom' do
content_type :json
if params['text'].present?
args = params['text'].split(' ', 2)
response = case args.first
when 'go', 'g' then server.go(args[1], params)
when 'ungo', 'ug' then server.ungo(args[1], params)
when 'list', 'l' then server.list(args[1], params)
when 'emoji', 'e' then server.emoji(args[1], params)
else server.help
end
response.to_json
else
''
end
end
get '/oauth' do
server.oauth(params)
redirect to('/thanks')
end
get '/' do
haml :landing
end
get '/privacy' do
haml :privacy
end
get '/contact' do
haml :contact
end
get '/thanks' do
haml :thanks
end