From f46cdf9ce957b03539bd4dc76a83ce439535d349 Mon Sep 17 00:00:00 2001 From: John Nunemaker Date: Thu, 16 Apr 2009 12:07:09 -0400 Subject: [PATCH] httpauth can now accept :ssl option to use https instead of http. --- History | 1 + lib/twitter/httpauth.rb | 7 ++++--- test/twitter/httpauth_test.rb | 20 ++++++++++++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/History b/History index abd0fa1c6..ca20982ee 100644 --- a/History +++ b/History @@ -1,6 +1,7 @@ 0.6.6 - April 16, 2009 * 1 minor enhancement * added ability to pass query parameters to user method + * httpauth can now accept :ssl option to use https instead of http 0.6.5 - April 15, 2009 * 1 bug fix diff --git a/lib/twitter/httpauth.rb b/lib/twitter/httpauth.rb index c6127f96b..9269e680c 100644 --- a/lib/twitter/httpauth.rb +++ b/lib/twitter/httpauth.rb @@ -1,13 +1,14 @@ module Twitter class HTTPAuth include HTTParty - base_uri 'http://twitter.com' format :plain - attr_reader :username, :password + attr_reader :username, :password, :options - def initialize(username, password) + def initialize(username, password, options={}) @username, @password = username, password + @options = {:ssl => false}.merge(options) + self.class.base_uri "http#{'s' if options[:ssl]}://twitter.com" end def get(uri, headers={}) diff --git a/test/twitter/httpauth_test.rb b/test/twitter/httpauth_test.rb index 3c1c99ea9..818636874 100644 --- a/test/twitter/httpauth_test.rb +++ b/test/twitter/httpauth_test.rb @@ -7,6 +7,26 @@ class HTTPAuthTest < Test::Unit::TestCase twitter.username.should == 'username' twitter.password.should == 'password' end + + should "accept options" do + twitter = Twitter::HTTPAuth.new('username', 'password', :ssl => true) + twitter.options.should == {:ssl => true} + end + + should "default ssl to false" do + twitter = Twitter::HTTPAuth.new('username', 'password') + twitter.options[:ssl].should be(false) + end + + should "use https if ssl is true" do + Twitter::HTTPAuth.expects(:base_uri).with('https://twitter.com') + twitter = Twitter::HTTPAuth.new('username', 'password', :ssl => true) + end + + should "use http if ssl is false" do + Twitter::HTTPAuth.expects(:base_uri).with('http://twitter.com') + twitter = Twitter::HTTPAuth.new('username', 'password', :ssl => false) + end end context "Client methods" do