Created
April 23, 2009 10:28
-
-
Save vikhyat/100443 to your computer and use it in GitHub Desktop.
Source to the app at http://pure-journey-47.heroku.com/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%w[ | |
rubygems | |
sinatra | |
dm-core | |
dm-timestamps | |
].each { |lib| require lib } | |
get '/' do | |
"You aren't supposed to be viewing this." | |
end | |
get '/send/:user/:from/:message' do | |
creator = {:user => params[:user], :from => params[:from], :content => params[:message], :time => Time.now} | |
@msg = Message.first(creator) | |
@msg = Message.create(creator) if @msg.nil? | |
end | |
get '/get/:user' do | |
@m = Message.all(:user => params[:user], :order => [:time.desc]) | |
@m = @m[0..20] | |
result = [] | |
@m.each do |i| | |
result << [ i.from, i.content, i.time != nil ? i.time.to_time.to_i : nil ] | |
end | |
"messages = #{result.inspect}" | |
end | |
# Database stuff | |
DataMapper.setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/db.sqlite3") | |
class Message | |
include DataMapper::Resource | |
property :id, Serial | |
property :content, String, :length => 255 | |
property :user, String, :length => 255 | |
property :from, String, :length => 255 | |
property :time, DateTime | |
end | |
DataMapper.auto_upgrade! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment