34 lines
550 B
Ruby
34 lines
550 B
Ruby
|
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
|