-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
60 lines (50 loc) · 1.15 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
class Gifhub < Sinatra::Base
set :root, File.dirname(__FILE__)
set :views, Proc.new { File.join(root, "app/views/") }
enable :sessions
# Methods
# --------
# def github
# @github ||= Github::Client.new(session[:access_token])
# end
def authenticated?
session[:access_token]
end
def authenticate!
haml :login, locals: { login_url: Github.auth_url }
end
# Lambdas
# --------
login = lambda do
if !authenticated?
authenticate!
else
haml :index
end
end
logout = lambda do
session[:access_token] = nil
redirect "/"
end
setup_user = lambda do
params[:installation_id]
redirect "/"
end
recieve_callback = lambda do
session[:access_token] = Github.retrieve_access_token(request.env["rack.request.query_hash"]["code"])
redirect "/"
end
recieve_payload = lambda do
github = Github::Client.new(request)
User.create(github.user) if github.installing?
github.create_comment
halt 200
end
# Routes
# --------
get "/", &login
get "/logout", &logout
get "/setup", &setup_user
get "/callback", &recieve_callback
post "/payload", &recieve_payload
end