You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
550 B

6 years ago
  1. require "sinatra"
  2. require "sinatra/json"
  3. require "sequel"
  4. NODES = {}
  5. Sequel.connect(ENV["DATABASE_URL"] || "sqlite://meet4eat.db")
  6. class Node < Sequel::Model
  7. def to_json(options={})
  8. {
  9. id: name,
  10. room: room
  11. }.to_json
  12. end
  13. end
  14. get '/nodes' do
  15. json({ nodes: Node.all })
  16. end
  17. put '/nodes/:id' do
  18. node = Node.where(name: params[:id]).first
  19. node ||= Node.new(name: params[:id])
  20. node.room = params[:room] || "default"
  21. node.save
  22. json("")
  23. end
  24. delete '/nodes/:id' do
  25. Node.where(name: params[:id]).delete
  26. json("")
  27. end