-
Notifications
You must be signed in to change notification settings - Fork 1
/
whiteroom.rb
49 lines (42 loc) · 986 Bytes
/
whiteroom.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
require 'rubygems'
require 'sinatra'
require 'active_record'
require 'geokit'
require 'json'
require 'rack/contrib/jsonp'
require 'lib/acts_as_mappable'
use Rack::JSONP
dbconfig = YAML.load(File.read('config/database.yml'))
ActiveRecord::Base.establish_connection dbconfig['production']
configure do
#LOGGER = Logger.new("sinatra.log")
#ActiveRecord::Base.logger = LOGGER
end
helpers do
def logger
LOGGER
end
end
class Waypoint < ActiveRecord::Base
acts_as_mappable :lat_column_name => :latitude, :lng_column_name => :longitude
end
get '/' do
{:foo => 'bar', :meh => true}.to_json
end
get '/nearby' do
@points = Waypoint.find(:all, :origin => [44.0559,-121.31], :within => 5)
content_type :json
@points.to_json
end
get '/new' do
a = {
:title => params[:title],
:description => params[:description],
:latitude => params[:latitude],
:longitude => params[:longitude]
}
w = Waypoint.create(a)
w.save
content_type :js
w.to_json
end