-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
40 lines (31 loc) · 942 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
require 'bundler/setup'
require 'sinatra'
require 'gittycat'
ID_KEY = 'GITHUB_CLIENT_ID'
SECRET_KEY = 'GITHUB_CLIENT_SECRET'
client_id = ENV[ID_KEY]
client_secret = ENV[SECRET_KEY]
raise "Expected environment variables #{ID_KEY} and #{SECRET_KEY}" if !client_id or !client_secret
set :protection, :except => :frame_options
configure :production do
set :public_folder, File.dirname(__FILE__) + "/dist"
end
get '/' do
@title = "GitHub widgets for your website"
erb :index
end
get '/follow/:user' do
code = params[:code]
if code
connection = GittyCat::Connection.new({
:client_id => client_id,
:client_secret => client_secret,
:code => code
})
connection.user.follow params[:user]
redirect "https://github.com/#{params[:user]}"
else
query = "scope=user&client_id=#{client_id}&redirect_uri=#{request.url}"
redirect "https://github.com/login/oauth/authorize?#{query}"
end
end