-
Notifications
You must be signed in to change notification settings - Fork 3
/
beer.rb
43 lines (33 loc) · 882 Bytes
/
beer.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
require "sinatra/base"
require "haml"
require "json"
Sinatra::Base.set :environment, ENV['RACK_ENV'] || "development"
RACK_ENV = Sinatra::Base.environment
APP_ROOT = File.dirname(__FILE__)
Dir["config/*.rb"].each {|file| require file }
Dir["models/*.rb"].each {|file| require file }
module BeerAndCode
class HomePage < Sinatra::Base
set :haml, :format => :html5
before /\.json$/ do
content_type 'application/json'
end
get '/' do
haml :index
end
get '/locations.json' do
{
:status => 'success',
:data => {
:locations => get_locations_for(request)
}
}.to_json
end
private
def get_locations_for(request)
lat, lng = request.params[:lat], request.params[:lng]
locations = Location.near(lat, lng).limit(10).all
locations.map(&:to_hash)
end
end
end