-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First shot at http auth seems to be working.
- Loading branch information
1 parent
9d4fd99
commit d713ecf
Showing
11 changed files
with
153 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require File.join(File.dirname(__FILE__), '..', 'lib', 'twitter') | ||
require File.join(File.dirname(__FILE__), 'helpers', 'config_store') | ||
require 'pp' | ||
|
||
config = ConfigStore.new("#{ENV['HOME']}/.twitter") | ||
|
||
httpauth = Twitter::HTTPAuth.new(config['email'], config['password']) | ||
base = Twitter::Base.new(httpauth) | ||
|
||
pp base.user_timeline | ||
pp base.verify_credentials |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module Twitter | ||
class HTTPAuth | ||
include HTTParty | ||
base_uri 'http://twitter.com' | ||
format :plain | ||
|
||
attr_reader :username, :password | ||
|
||
def initialize(username, password) | ||
@username, @password = username, password | ||
end | ||
|
||
def get(uri, headers={}) | ||
self.class.get(uri, :headers => headers, :basic_auth => basic_auth) | ||
end | ||
|
||
def post(uri, body={}, headers={}) | ||
self.class.post(uri, :body => body, :headers => headers, :basic_auth => basic_auth) | ||
end | ||
|
||
private | ||
def basic_auth | ||
@basic_auth ||= {:username => @username, :password => @password} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
require File.dirname(__FILE__) + '/../test_helper' | ||
|
||
class HTTPAuthTest < Test::Unit::TestCase | ||
context "Creating new instance" do | ||
should "should take user and password" do | ||
twitter = Twitter::HTTPAuth.new('username', 'password') | ||
twitter.username.should == 'username' | ||
twitter.password.should == 'password' | ||
end | ||
end | ||
|
||
context "Client methods" do | ||
setup do | ||
@twitter = Twitter::HTTPAuth.new('username', 'password') | ||
end | ||
|
||
should "be able to get" do | ||
stub_get('http://twitter.com:80/statuses/user_timeline.json', 'user_timeline.json') | ||
response = @twitter.get('/statuses/user_timeline.json') | ||
response.should == fixture_file('user_timeline.json') | ||
end | ||
|
||
should "be able to get with headers" do | ||
@twitter.class.expects(:get).with( | ||
'/statuses/user_timeline.json', { | ||
:basic_auth => {:username => 'username', :password => 'password'}, | ||
:headers => {'Foo' => 'Bar'} | ||
} | ||
).returns(fixture_file('user_timeline.json')) | ||
@twitter.get('/statuses/user_timeline.json', {'Foo' => 'Bar'}) | ||
end | ||
|
||
should "be able to post" do | ||
stub_post('http://twitter.com:80/statuses/update.json', 'status.json') | ||
response = @twitter.post('/statuses/update.json', :text => 'My update.') | ||
response.should == fixture_file('status.json') | ||
end | ||
|
||
should "be able to post with headers" do | ||
@twitter.class.expects(:post).with( | ||
'/statuses/update.json', { | ||
:headers => {'Foo' => 'Bar'}, | ||
:body => {:text => 'My update.'}, | ||
:basic_auth => {:username => 'username', :password => 'password'} | ||
} | ||
).returns(fixture_file('status.json')) | ||
@twitter.post('/statuses/update.json', {:text => 'My update.'}, {'Foo' => 'Bar'}) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.