-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.rb
100 lines (80 loc) · 2.17 KB
/
app.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#### Gem dependencies
require 'rubygems'
require 'sinatra'
require 'haml'
require 'dm-core'
require 'dm-serializer'
require 'pusher'
if ENV['PUSHER_APP_ID']
Pusher.app_id = ENV['PUSHER_APP_ID']
Pusher.key = ENV['PUSHER_KEY']
Pusher.secret = ENV['PUSHER_SECRET']
else
Pusher.app_id = '17'
Pusher.key = 'c9f08e8c50f6f0cfb136'
Pusher.secret = '5eeec6ac0f4da8ad248a'
end
PUSHER_CHANNEL = 'retrospectiveapp-' + Sinatra::Application.environment.to_s
#### DB Models
class Note
include DataMapper::Resource
property :id, Serial
property :text, Text
property :x, Integer
property :y, Integer
property :w, Integer
property :h, Integer
property :color, String
property :angle, Integer
end
#### Configuration
configure :development do
require 'do_sqlite3'
DataMapper.setup(:default, "sqlite3://#{Dir.pwd}/retrospective.db")
end
configure :production do
require 'do_postgres'
DataMapper.setup(:default, ENV['DATABASE_URL'] || 'postgres://localhost/retrospectiveapp-production')
end
#### App Routes
get '/' do
haml :index
end
get '/notes.json' do
content_type 'text/json', :charset => 'utf-8'
Note.all.to_json
end
post '/notes.json' do
content_type 'text/json', :charset => 'utf-8'
n = Note.new(params[:note])
n.save
Pusher[PUSHER_CHANNEL].trigger_async('note-create', n.to_json)
n.to_json
end
put '/notes/:id/softupdate.json' do
content_type 'text/json', :charset => 'utf-8'
Pusher[PUSHER_CHANNEL].trigger_async('note-softupdate', params[:note].to_json, params[:socket_id])
params[:note].to_json
end
put '/notes/:id.json' do |id|
content_type 'text/json', :charset => 'utf-8'
n = Note.get(id)
n.update(params[:note])
Pusher[PUSHER_CHANNEL].trigger_async('note-update', n.to_json)
n.to_json
end
delete '/notes/:id.json' do |id|
content_type 'text/json', :charset => 'utf-8'
n = Note.get(id).destroy!
Pusher[PUSHER_CHANNEL].trigger_async('note-destroy', {:id => id}.to_json)
{:id => id}.to_json
end
#### CSS Routes
get '/reset.css' do
content_type 'text/css', :charset => 'utf-8'
sass :reset
end
get '/app.css' do
content_type 'text/css', :charset => 'utf-8'
sass :app
end