configure do
set server: 'thin', connections: []
set :app_file, __FILE__
set :port, ENV['PORT']
set :public_folder, File.dirname(__FILE__) + '/public'
end
get '/stream', provides: 'text/event-stream' do
stream :keep_open do |out|
settings.connections << out
out.callback { settings.connections.delete(out) }
end
end
post '/update/contact/:id' do
@contact = Contact.get(params[:id])
@contact.update(params[:contact])
settings.connections.each { |out| out << "data: #{@contact.account_id} Contact #{@contact.id} #{@contact.first_name} #{@contact.last_name}\n\n" }
204
end