Permalink
Browse files

updating docs

  • Loading branch information...
1 parent fbf0116 commit ef6270ade5d5fe4af7e9a1a18996c80b15176211 @baroquebobcat committed Mar 11, 2010
Showing with 24 additions and 8 deletions.
  1. +2 −0 README.rdoc
  2. +1 −0 Rakefile
  3. +2 −2 lib/sinatra-twitter-oauth.rb
  4. +17 −5 lib/sinatra-twitter-oauth/helpers.rb
  5. +2 −1 sinatra-twitter-oauth.gemspec
View
@@ -13,6 +13,7 @@ A simple sinatra extension for using twitter oauth for login
:callback => 'example.com/foo/auth'
get '/' do
login_required
+ "hello #{user}"
end
=== using Sinatra::Base
@@ -25,6 +26,7 @@ A simple sinatra extension for using twitter oauth for login
:callback => 'example.com/foo/auth'
get '/' do
login_required
+ "hello #{user}"
end
end
== Note on Patches/Pull Requests
View
@@ -11,6 +11,7 @@ begin
gem.homepage = "http://github.com/baroquebobcat/sinatra-twitter-oauth"
gem.authors = ["Nick Howard"]
gem.add_development_dependency "rspec", ">= 1.2.9"
+ gem.rdoc_options << "--main" << "README.rdoc"
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
end
Jeweler::GemcutterTasks.new
@@ -24,14 +24,14 @@ module TwitterOAuth
:login_template => {:text=>'<a href="/connect">Login using Twitter</a>'}
}
- def self.registered app
+ def self.registered app # :nodoc:
app.helpers Helpers
app.enable :sessions
app.set :twitter_oauth_config, DEFAULT_CONFIG
app.get '/login' do
- redirect '/' if @user
+ redirect '/' if user
login_template = options.twitter_oauth_config[:login_template]
@@ -1,26 +1,35 @@
module Sinatra::TwitterOAuth
+ #Helpers exposed by the extension.
+ #
module Helpers
+ # The current logged in user
+ def user
+ @user
+ end
+
+ # Redirects to login unless there is an authenticated user
def login_required
setup_client
@user = ::TwitterOAuth::User.new(@client, session[:user]) if session[:user]
@rate_limit_status = @client.rate_limit_status
- redirect '/login' unless @user
+ redirect '/login' unless user
end
- def setup_client
+
+ def setup_client # :nodoc:
@client ||= ::TwitterOAuth::Client.new(
:consumer_secret => options.twitter_oauth_config[:secret],
:consumer_key => options.twitter_oauth_config[:key],
:token => session[:access_token],
:secret => session[:secret_token]
)
- end
+ end
- def get_request_token
+ def get_request_token # :nodoc:
setup_client
begin
@@ -30,7 +39,7 @@ def get_request_token
end
end
- def get_access_token
+ def get_access_token # :nodoc:
setup_client
begin
@@ -44,6 +53,7 @@ def get_access_token
end
end
+ # gets the request token and redirects to twitter's OAuth endpoint
def redirect_to_twitter_auth_url
request_token = get_request_token
@@ -53,6 +63,7 @@ def redirect_to_twitter_auth_url
redirect request_token.authorize_url.gsub('authorize','authenticate')
end
+ # attempts to get the access token(MUST be used after user has been redirected back from twitter)
def authenticate!
access_token = get_access_token
@@ -67,6 +78,7 @@ def authenticate!
end
end
+ #removes all the session data defined by the extension
def clear_oauth_session
session[:user] = nil
session[:request_token] = nil
@@ -26,11 +26,12 @@ Gem::Specification.new do |s|
"lib/sinatra-twitter-oauth.rb",
"lib/sinatra-twitter-oauth/helpers.rb",
"lib/sinatra-twitter-oauth/twitter_oauth_ext.rb",
+ "sinatra-twitter-oauth.gemspec",
"spec/sinatra-twitter-oauth_spec.rb",
"spec/spec_helper.rb"
]
s.homepage = %q{http://github.com/baroquebobcat/sinatra-twitter-oauth}
- s.rdoc_options = ["--charset=UTF-8"]
+ s.rdoc_options = ["--charset=UTF-8", "--main", "README.rdoc"]
s.require_paths = ["lib"]
s.rubygems_version = %q{1.3.5}
s.summary = %q{A Sinatra Extension that simplifies using twitter for login and authentication.}

0 comments on commit ef6270a

Please sign in to comment.