Skip to content

Instantly share code, notes, and snippets.

@amacgregor

amacgregor/sbuttler.rb Secret

Created Jun 18, 2011
Embed
What would you like to do?
sbuttler.rb
require 'sinatra'
require 'datamapper'
require 'twitter'
require 'rubygems'
require 'resque_scheduler'
require 'system_timer'
DataMapper::setup(:default, "sqlite3://#{Dir.pwd}/sbuttler.db")
Resque.redis = Redis.new('localhost')
class Note
include DataMapper::Resource
property :id, Serial
property :content, Text, :required => true
property :complete, Boolean, :required => true, :default => false
property :publish_at, DateTime
property :created_at, DateTime
property :updated_at, DateTime
end
Twitter.configure do |config|
config.consumer_key = 'XXXXXX'
config.consumer_secret = 'XXXXXX'
config.oauth_token = 'XXXXXX'
config.oauth_token_secret = 'XXXXXX'
end
client = Twitter::Client.new
DataMapper.finalize.auto_upgrade!
get '/' do
@notes = Note.all :order => :id.desc
@title = 'All Notes'
erb :home
end
get '/ajaxlist' do
@notes = Note.all :order => :id.desc
@title = 'All Notes'
erb :list, :layout => (request.xhr? ? false : :layout)
end
post '/' do
n = Note.new
n.content = params[:content]
n.created_at = Time.now
n.updated_at = Time.now
n.publish_at = Time.now
n.save
redirect '/'
end
get '/:id' do
@note = Note.get params[:id]
@title = "Edit note ##{params[:id]}"
erb :edit
end
put '/:id' do
n = Note.get params[:id]
n.content = params[:content]
n.complete = params[:complete] ? 1 : 0
n.updated_at = Time.now
n.save
redirect '/'
end
get '/:id/delete' do
n = Note.get params[:id]
n.destroy
redirect '/'
end
#---Original Delete methods
#get '/:id/delete' do
# @note = Note.get params[:id]
# @title = "Confirm deletion of note ##{params[:id]}"
# erb :delete
#end
#
#delete '/:id' do
# n = Note.get params[:id]
# n.destroy
# redirect '/'
#end
get '/:id/complete' do
n = Note.get params[:id]
n.complete = n.complete ? 0 : 1 # flip it
n.updated_at = Time.now
n.save
redirect '/'
end
get '/:id/publish' do
n = Note.get params[:id]
n.complete = n.complete ? 0 : 1 # flip it
n.updated_at = Time.now
n.save
client.update(n.content)
redirect '/'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.