-
Notifications
You must be signed in to change notification settings - Fork 58
/
app.rb
46 lines (37 loc) · 1.31 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
require 'sinatra'
require 'githubchart'
require './color.rb'
# Examples of nice colors to try out to start with:
# blue: 409ba5
# red: 720100
# green: 44a340
get '/' do
send_file File.join(settings.public_folder, 'index.html')
end
get '/:username' do
#default color scheme used by github
headers 'Content-Type' => "image/svg+xml"
headers 'Cache-Control' => "max-age=#{60*60*24}"
username = params[:username].chomp('.svg') #Chomp off the .svg extension to be backwards compatible
svg = GithubChart.new(user: username).render('svg')
stream do |out|
out << svg
end
end
get '/:base/:username' do
headers 'Cache-Control' => "max-age=#{60*60*24}"
headers 'Content-Type' => "image/svg+xml"
username = params[:username].chomp('.svg')
#Makes API backwards compatible
if(params[:base] == "teal" || params[:base] == "halloween" || params[:base] == "default")
scheme = COLOR_SCHEMES[params[:base].to_sym]
else
#this case will be executed a majority of the time
base_color = '#'+params[:base]
scheme = ['#EEEEEE', lighten_color(base_color, 0.3), lighten_color(base_color, 0.2), base_color, darken_color(base_color, 0.8)]
end
svg = GithubChart.new(user: username, colors: scheme).render('svg')
stream do |out|
out << svg
end
end