This repository has been archived by the owner on Dec 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.rb
61 lines (53 loc) · 1.35 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
61
require 'sinatra'
require 'yaml'
require 'open-uri'
require 'nokogiri'
require 'digest/md5'
require 'time'
require 'json'
require 'haml'
require 'memcached'
require 'dalli'
require File.expand_path(File.join(File.dirname(__FILE__), 'lib/classes/muni'))
require File.expand_path(File.join(File.dirname(__FILE__), 'lib/support/sinatra-dalli'))
DAY = 24 * 60 * 60
enable :logging
set :cache_namespace, "muni"
set :cache_enable, true
set :cache_logging, true
get '/' do
haml :index
end
get '/muni.json' do
cache 'arrivals', :expiry => 45 do
puts "fetching arrivals"
@@faves ||= YAML.load_file('settings.yml')
arrivals = Muni.new.arrivals(@@faves)
arrivals.to_json
end
end
get '/browse' do
# cache 1 day
cache 'routes', :expiry => 1 * DAY do
@routes = Muni.new.routes
haml :browse_routes
end
end
get '/browse/:tag' do |tag|
cache "route_#{tag}", :expiry => 1 * DAY do
@route_info = Muni.new.route_info(tag)
haml :browse_route_info
end
end
get '/cache.manifest' do
@cached_files = Dir.glob(File.join('public', 'css', '*.css')) +
Dir.glob(File.join('public', 'js', '*.js')) +
Dir.glob(File.join('public', 'fonts', '*.{eot,svg,ttf,woff}'))
file = @cached_files.pop
mtime = File.mtime(file)
@rev_date = @cached_files.inject(mtime) do |latest, file|
mtime = File.mtime(file)
(mtime > latest) ? mtime : latest
end
erb :cache_manifest
end