Skip to content

Commit

Permalink
httpauth can now accept :ssl option to use https instead of http.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnunemaker committed Apr 16, 2009
1 parent 6f18cbb commit f46cdf9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions History
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 4 additions & 3 deletions lib/twitter/httpauth.rb
Original file line number Diff line number Diff line change
@@ -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={})
Expand Down
20 changes: 20 additions & 0 deletions test/twitter/httpauth_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f46cdf9

Please sign in to comment.