Skip to content

Commit

Permalink
Added 3rd party api endpoint support for Tumblr, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
Wynn Netherland committed Dec 18, 2009
1 parent 2571cd8 commit c5550f1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
5 changes: 2 additions & 3 deletions lib/twitter/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def initialize(client)

# Options: since_id, max_id, count, page
def home_timeline(query={})
perform_get('http://api.twitter.com/1/statuses/home_timeline.json', :query => query)
perform_get('/statuses/home_timeline.json', :query => query)
end

# Options: since_id, max_id, count, page, since
Expand Down Expand Up @@ -218,8 +218,7 @@ def list_delete(list_owner_username, slug)
end

def lists(list_owner_username=nil)
path = "http://api.twitter.com/1"
path += "/#{list_owner_username}" if list_owner_username
path = "/#{list_owner_username}" if list_owner_username
path += "/lists.json"
perform_get(path)
end
Expand Down
3 changes: 2 additions & 1 deletion lib/twitter/httpauth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ class HTTPAuth
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"
options[:api_endpoint] ||= "twitter.com"
self.class.base_uri "http#{'s' if options[:ssl]}://#{options[:api_endpoint]}"
end

def get(uri, headers={})
Expand Down
16 changes: 13 additions & 3 deletions test/twitter/base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class BaseTest < Test::Unit::TestCase

context "hitting the api" do
should "be able to get home timeline" do
stub_get('http://api.twitter.com/1/statuses/home_timeline.json', 'home_timeline.json')
stub_get('/statuses/home_timeline.json', 'home_timeline.json')
timeline = @twitter.home_timeline
timeline.size.should == 20
first = timeline.first
Expand Down Expand Up @@ -219,7 +219,7 @@ class BaseTest < Test::Unit::TestCase
end

should "be able to view lists for the authenticated user" do
stub_get('http://api.twitter.com/1/pengwynn/lists.json', 'lists.json')
stub_get('/pengwynn/lists.json', 'lists.json')
lists = @twitter.lists('pengwynn').lists
lists.size.should == 1
lists.first.name.should == 'Rubyists'
Expand Down Expand Up @@ -316,7 +316,17 @@ class BaseTest < Test::Unit::TestCase
end

end
end

context "when using a non-twitter service" do
setup do
@twitter = Twitter::Base.new(Twitter::HTTPAuth.new('[email protected]', 'mypass', :api_endpoint => 'tumblr.com'))
end


should "get the home timeline" do
stub_get('http://wynn%40example.com:[email protected]/statuses/home_timeline.json', 'home_timeline.json')
timeline = @twitter.home_timeline
timeline.size.should == 20
end
end
end

0 comments on commit c5550f1

Please sign in to comment.