Permalink
Browse files

Unathenticated list timeline method added

  • Loading branch information...
1 parent 358ff33 commit aed3a298b613a508bb9caf93afc7f12c50626ad7 @spastorino committed Jan 29, 2010
Showing with 40 additions and 0 deletions.
  1. +7 −0 lib/twitter.rb
  2. +33 −0 test/twitter_test.rb
View
@@ -56,6 +56,13 @@ def self.timeline(id, options={})
response = HTTParty.get("http://twitter.com/statuses/user_timeline/#{id}.json", :query => options, :format => :json)
response.map{|tweet| Hashie::Mash.new tweet}
end
+
+ # :per_page = max number of statues to get at once
+ # :page = which page of tweets you wish to get
+ def self.list_timeline(list_owner_username, slug, query = {})
+ response = HTTParty.get("http://api.twitter.com/1/#{list_owner_username}/lists/#{slug}/statuses.json", :query => query, :format => :json)
+ response.map{|tweet| Hashie::Mash.new tweet}
+ end
end
directory = File.expand_path(File.dirname(__FILE__))
View
@@ -43,4 +43,37 @@ class TwitterTest < Test::Unit::TestCase
ids = Twitter.follower_ids('jnunemaker')
ids.size.should == 1252
end
+
+ context "when using lists" do
+
+ should "be able to view list timeline" do
+ stub_get('http://api.twitter.com:80/1/pengwynn/lists/rubyists/statuses.json', 'list_statuses.json')
+ tweets = Twitter.list_timeline('pengwynn', 'rubyists')
+ tweets.size.should == 20
+ tweets.first.id.should == 5272535583
+ tweets.first.user.name.should == 'John Nunemaker'
+ end
+
+ should "be able to limit number of tweets in list timeline" do
+ stub_get('http://api.twitter.com:80/1/pengwynn/lists/rubyists/statuses.json?per_page=1', 'list_statuses_1_1.json')
+ tweets = Twitter.list_timeline('pengwynn', 'rubyists', :per_page => 1)
+ tweets.size.should == 1
+ tweets.first.id.should == 5272535583
+ tweets.first.user.name.should == 'John Nunemaker'
+ end
+
+ should "be able to paginate through the timeline" do
+ stub_get('http://api.twitter.com:80/1/pengwynn/lists/rubyists/statuses.json?page=1&per_page=1', 'list_statuses_1_1.json')
+ stub_get('http://api.twitter.com:80/1/pengwynn/lists/rubyists/statuses.json?page=2&per_page=1', 'list_statuses_2_1.json')
+ tweets = Twitter.list_timeline('pengwynn', 'rubyists', { :page => 1, :per_page => 1 })
+ tweets.size.should == 1
+ tweets.first.id.should == 5272535583
+ tweets.first.user.name.should == 'John Nunemaker'
+ tweets = Twitter.list_timeline('pengwynn', 'rubyists', { :page => 2, :per_page => 1 })
+ tweets.size.should == 1
+ tweets.first.id.should == 5264324712
+ tweets.first.user.name.should == 'John Nunemaker'
+ end
+
+ end
end

0 comments on commit aed3a29

Please sign in to comment.