-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.rb
48 lines (37 loc) · 929 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
require 'sinatra'
require './scraper.rb'
require './generator.rb'
require_relative 'rate_limiter'
class RuneFlex < Sinatra::Base
use RateLimiter, limit: 50, period: 60
before do
logger.info "Received request: #{request.path}"
end
# get '/' do
# 'this endpoint is for testing purposes!'
# end
get '/flex' do
content_type 'image/svg+xml'
unless params[:rsn]
status 400
return 'error: missing username params'
end
if params[:rsn].length > 12
status 400
return 'error: username must be 12 characters or less'
end
rsn = params[:rsn]
scraper = Scraper.new(rsn.to_s)
stats = scraper.stats
generator = Generator.new()
generator.generate_stats_svg(stats, rsn)
end
#run! if app_file == $0
end
# if __FILE__ == $0
# require 'puma'
# RuneFlex.run!
# end
if __FILE__ == $0
RuneFlex.run!({ server: 'puma', port: ENV['PORT'] || 4567 })
end