meet2eat/app.rb

34 lines
550 B
Ruby
Raw Permalink Normal View History

2015-02-03 22:16:12 +00:00
require "sinatra"
require "sinatra/json"
require "sequel"
NODES = {}
Sequel.connect(ENV["DATABASE_URL"] || "sqlite://meet4eat.db")
class Node < Sequel::Model
def to_json(options={})
{
id: name,
room: room
}.to_json
end
end
get '/nodes' do
json({ nodes: Node.all })
end
put '/nodes/:id' do
node = Node.where(name: params[:id]).first
node ||= Node.new(name: params[:id])
node.room = params[:room] || "default"
node.save
json("")
end
delete '/nodes/:id' do
Node.where(name: params[:id]).delete
json("")
end