Permalink
Browse files

Added the ability to sign in with twitter instead of authorizing

  • Loading branch information...
1 parent 709e7be commit 68b6252a21e7e773d108027f693b8378593e21ad @jnunemaker jnunemaker committed May 19, 2009
Showing with 25 additions and 4 deletions.
  1. +4 −0 History
  2. +11 −4 lib/twitter/oauth.rb
  3. +10 −0 test/twitter/oauth_test.rb
View
@@ -1,3 +1,7 @@
+0.6.11 - May 18, 2009
+* 1 minor addition
+ * Added the ability to sign in with twitter instead of authorizing
+
0.6.10 - May 18, 2009
* 1 cool addition
* Added full support for trends - current, daily and weekly (even allowing excluding of hashtags and for specific dates)
View
@@ -3,14 +3,21 @@ class OAuth
extend Forwardable
def_delegators :access_token, :get, :post
- attr_reader :ctoken, :csecret
+ attr_reader :ctoken, :csecret, :consumer_options
- def initialize(ctoken, csecret)
- @ctoken, @csecret = ctoken, csecret
+ # Options
+ # :sign_in => true to just sign in with twitter instead of doing oauth authorization
+ # (http://apiwiki.twitter.com/Sign-in-with-Twitter)
+ def initialize(ctoken, csecret, options={})
+ @ctoken, @csecret, @consumer_options = ctoken, csecret, {}
+
+ if options[:sign_in]
+ @consumer_options[:authorize_path] = '/oauth/authenticate'
+ end
end
def consumer
- @consumer ||= ::OAuth::Consumer.new(@ctoken, @csecret, {:site => 'http://twitter.com'})
+ @consumer ||= ::OAuth::Consumer.new(@ctoken, @csecret, {:site => 'http://twitter.com'}.merge(consumer_options))
end
def request_token
View
@@ -8,6 +8,16 @@ class OAuthTest < Test::Unit::TestCase
twitter.csecret.should == 'secret'
end
+ should "set autorization path to '/oauth/authorize' by default" do
+ twitter = Twitter::OAuth.new('token', 'secret')
+ twitter.consumer.options[:authorize_path].should == '/oauth/authorize'
+ end
+
+ should "set autorization path to '/oauth/authenticate' if sign_in_with_twitter" do
+ twitter = Twitter::OAuth.new('token', 'secret', :sign_in => true)
+ twitter.consumer.options[:authorize_path].should == '/oauth/authenticate'
+ end
+
should "have a consumer" do
consumer = mock('oauth consumer')
OAuth::Consumer.expects(:new).with('token', 'secret', {:site => 'http://twitter.com'}).returns(consumer)

0 comments on commit 68b6252

Please sign in to comment.