-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.rb
executable file
·76 lines (52 loc) · 1.55 KB
/
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
require 'rubygems'
require 'sinatra/base'
require 'haml'
require 'sinatra-twitter-oauth'
#
# Started with http://github.com/moomerman/sinitter,
# moomerman's example of how to use twitter_oauth,
# and modified it.
#
#
class TwitterListManager < Sinatra::Base
register Sinatra::TwitterOAuth
configure do
enable :methodoverride
enable :logging
set :views, File.dirname(__FILE__) + '/views'
self.twitter_oauth_config= {
:key =>ENV['TWITTER_OAUTH_KEY'],
:secret =>ENV['TWITTER_OAUTH_SECRET'],
:callback => ENV['TWITTER_OAUTH_CALLBACK'],
:login_template => {:haml => :login}
}
end
get '/' do
login_required
@lists = user.lists.sort{|a,b| a.name <=> b.name }
haml :lists
end
put '/:list_name' do
login_required
@list = user.list params[:list_name]
pass unless @list
if params['list']['remove_members']
@list.remove_members params['list']['remove_members'].keys
end
unless !params['list']['new_members'] || params['list']['new_members'].empty?
@list.add_members params['list']['new_members'].split
end
redirect '/'
end
post '/new_list' do
login_required
@list = user.new_list params['list']['name'], params['list']['private'] ? {:mode=>'private'} : {}
@list.add_members params['list']['members'].split unless params['list']['members'].empty?
redirect '/'
end
delete '/:list_name' do
login_required
user.destroy_list params[:list_name]
redirect '/'
end
end