Skip to content

Commit

Permalink
Introduce locations
Browse files Browse the repository at this point in the history
  • Loading branch information
jhwist committed Apr 17, 2012
1 parent e78a1d2 commit d70d5a2
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion loctrack.rb
@@ -1,3 +1,9 @@
class Locations
include Mongoid::Document
field :when, type => :DateTime
field :where, type => :Array
end

class Counter
include Mongoid::Document

Expand Down Expand Up @@ -36,10 +42,27 @@ class Loctrack < Sinatra::Base
uri = URI.parse(ENV['MONGOHQ_URL'])
config.master = conn.db(uri.path.gsub(/^\//, ''))
else
config.master = Mongo::Connection.from_uri("mongodb://localhost:27017").db('test')
config.master = Mongo::Connection.from_uri("mongodb://localhost:27017").db('locations')
end
end

get '/api/v1/parked/:id' do
"Looking up #{params[:name]}"
loc = Locations.get(params[:id])
if loc.nil? then
status 404
else
status 200
body(loc.to_json)
end
end

# curl -i -H "Accept: application/json" -X PUT -d '{"when":"2001-01-01 2:00:00","lat":48,"long":11}' http://localhost:5000/api/v1/parked
put '/api/v1/parked' do
data = JSON.parse(request.body.gets.as_json)
end


get '/' do
@counter = Counter.increment.to_s
gon.locations = [['15-02-2012 - 07.50', 48.05514872074127,11.663317680358887],
Expand Down

0 comments on commit d70d5a2

Please sign in to comment.