-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.rb
More file actions
33 lines (30 loc) · 819 Bytes
/
app.rb
File metadata and controls
33 lines (30 loc) · 819 Bytes
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
require "rubygems"
require "bundler/setup"
Bundler.require
require 'csv'
require 'active_support/all'
class App < Sinatra::Base
enable :logging
use Rack::Session::Cookie
#register Barista::Integration::Sinatra
set :protection, :except => :frame_options
get '/' do
File.read(File.join('public', 'paper.html'))
end
get '/countries' do
content_type :json
countries = []
year = params[:year] || 2004
CSV.foreach("#{year}.csv") do |line|
country = {}
country['name'] = line[0]
country['gold'] = line[1].to_i
country['silver'] = line[2].to_i
country['bronze'] = line[3].to_i
country['gdp'] = line[4].to_i
country['gdp'] = rand(5000) if line[4] == "0" #TODO: fix missing GDP data
countries << country
end
countries.to_json
end
end