Permalink
Browse files

initial commit

  • Loading branch information...
1 parent 8cca05f commit 39248c3acc2fc94f67c4f134774d8648e94c1e57 @mirven mirven committed Nov 16, 2009
Showing with 83 additions and 0 deletions.
  1. +13 −0 README
  2. +63 −0 app.rb
  3. +2 −0 config.ru
  4. +5 −0 views/index.haml
View
@@ -0,0 +1,13 @@
+directions using heroku for hosting:
+
+create twitter app at http://twitter.com/apps
+for callback url use http://<appname>.heroku.com/auth
+note consumer key and consumer secret
+
+heroku create <appname>
+heroku config:add consumer_key=<consumer key from twitter> consumer_secret=<consume secret from twitter>
+git push heroku master
+
+inspired by
+http://github.com/filiptepper/sinatra-oauth-1.0a-example
+http://github.com/moomerman/sinitter
View
@@ -0,0 +1,63 @@
+require "rubygems"
+require "sinatra"
+require "oauth"
+require "oauth/consumer"
+require 'grackle'
+require 'haml'
+
+enable :sessions
+
+before do
+ session[:oauth] ||= {}
+
+ consumer_key = ENV["consumer_key"]
+ consumer_secret = ENV["consumer_secret"]
+
+ @consumer ||= OAuth::Consumer.new(consumer_key, consumer_secret, :site => "http://twitter.com")
+
+ if !session[:oauth][:request_token].nil? && !session[:oauth][:request_token_secret].nil?
+ @request_token = OAuth::RequestToken.new(@consumer, session[:oauth][:request_token], session[:oauth][:request_token_secret])
+ end
+
+ if !session[:oauth][:access_token].nil? && !session[:oauth][:access_token_secret].nil?
+ @access_token = OAuth::AccessToken.new(@consumer, session[:oauth][:access_token], session[:oauth][:access_token_secret])
+ end
+
+ if @access_token
+ @client = Grackle::Client.new(:auth => {
+ :type => :oauth,
+ :consumer_key => consumer_key,
+ :consumer_secret => consumer_secret,
+ :token => @access_token.token,
+ :token_secret => @access_token.secret
+ })
+ end
+end
+
+get "/" do
+ if @access_token
+ @statuses = @client.statuses.friends_timeline? :count => 100
+ haml :index
+ else
+ '<a href="/request">Sign On</a>'
+ end
+end
+
+get "/request" do
+ @request_token = @consumer.get_request_token(:oauth_callback => "http://#{request.host}/auth")
+ session[:oauth][:request_token] = @request_token.token
+ session[:oauth][:request_token_secret] = @request_token.secret
+ redirect @request_token.authorize_url
+end
+
+get "/auth" do
+ @access_token = @request_token.get_access_token :oauth_verifier => params[:oauth_verifier]
+ session[:oauth][:access_token] = @access_token.token
+ session[:oauth][:access_token_secret] = @access_token.secret
+ redirect "/"
+end
+
+get "/logout" do
+ session[:oauth] = {}
+ redirect "/"
+end
View
@@ -0,0 +1,2 @@
+require 'app'
+run Sinatra::Application
View
@@ -0,0 +1,5 @@
+%html
+ %body
+ %ul
+ - @statuses.each do |status|
+ %li= status.text

0 comments on commit 39248c3

Please sign in to comment.