Created
December 1, 2012 13:18
-
-
Save uasi/4182217 to your computer and use it in GitHub Desktop.
Sinatra starter kit
This file contains 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
require 'bundler' | |
Bundler.require | |
### Settings | |
enable :logging | |
enable :sessions | |
use OmniAuth::Builder do | |
provider :twitter, ENV['TWITTER_CONSUMER_KEY'], | |
ENV['TWITTER_CONSUMER_SECRET'] | |
end | |
### Helpers and utils | |
helpers do | |
def logged_in? | |
!!session[:uid] | |
end | |
end | |
def auth | |
request.env['omniauth.auth'] | |
end | |
def twitter | |
Twitter::Client.new( | |
consumer_key: ENV['TWITTER_CONSUMER_KEY'], | |
consumer_secret: ENV['TWITTER_CONSUMER_SECRET'], | |
oauth_token: session[:oauth_token], | |
oauth_token_secret: session[:oauth_secret], | |
) | |
end | |
### Actions | |
get '/' do | |
slim :index | |
end | |
get '/auth/twitter/callback' do | |
session[:uid] = auth.uid | |
session[:nickname] = auth.info.nickname | |
session[:oauth_token] = auth.credentials.token | |
session[:oauth_secret] = auth.credentials.secret | |
redirect '/' | |
end | |
get '/logout' do | |
session[:uid] = nil | |
session[:nickname] = nil | |
session[:oauth_token] = nil | |
session[:oauth_secret] = nil | |
redirect '/' | |
end |
This file contains 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
require './app.rb' | |
run Sinatra::Application |
This file contains 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
source :rubygems | |
gem 'thin' | |
gem 'sinatra' | |
gem 'sinatra-flash', require: 'sinatra/flash' | |
gem 'slim' | |
gem 'twitter' | |
gem 'omniauth' | |
gem 'omniauth-twitter' | |
group :development do | |
gem 'watchr' | |
end |
This file contains 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
def files | |
Regexp.union( | |
%r{app\.rb}, | |
%r{config\.ru}, | |
%r{views/.*\.slim}, | |
) | |
end | |
watch(files) { system('touch tmp/restart.txt') } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment