Skip to content
Browse files

added pagination support to base.list_timeline along with correspondi…

…ng tests
  • Loading branch information...
1 parent 36b07be commit 591d31a45b1a360d5743d2bf3966e7e9b563b9b7 Chen committed Dec 16, 2009
Showing with 27 additions and 2 deletions.
  1. +4 −2 lib/twitter/base.rb
  2. +1 −0 test/fixtures/list_statuses_1_1.json
  3. +1 −0 test/fixtures/list_statuses_2_1.json
  4. +21 −0 test/twitter/base_test.rb
View
6 lib/twitter/base.rb
@@ -228,8 +228,10 @@ def list(list_owner_username, slug)
perform_get("/#{list_owner_username}/lists/#{slug}.json")
end
- def list_timeline(list_owner_username, slug)
- perform_get("/#{list_owner_username}/lists/#{slug}/statuses.json")
+ # :per_page = max number of statues to get at once
+ # :page = which page of tweets you wish to get
+ def list_timeline(list_owner_username, slug, query = {})
+ perform_get("/#{list_owner_username}/lists/#{slug}/statuses.json", :query => query)
end
def memberships(list_owner_username)
View
1 test/fixtures/list_statuses_1_1.json
@@ -0,0 +1 @@
+[{"geo":null,"truncated":false,"source":"<a href=\"http://www.atebits.com/\" rel=\"nofollow\">Tweetie</a>","created_at":"Thu Oct 29 23:27:15 +0000 2009","favorited":false,"in_reply_to_user_id":null,"in_reply_to_status_id":null,"user":{"notifications":false,"favourites_count":115,"profile_link_color":"2FC2EF","description":"I make things simple.","following":false,"profile_background_tile":false,"geo_enabled":false,"profile_background_color":"1A1B1F","profile_image_url":"http://a3.twimg.com/profile_images/61024905/black250_normal.jpg","verified":false,"profile_sidebar_fill_color":"252429","url":"http://railstips.org/about","screen_name":"jnunemaker","created_at":"Sun Aug 13 22:56:06 +0000 2006","profile_sidebar_border_color":"181A1E","followers_count":1659,"protected":false,"statuses_count":6122,"time_zone":"Indiana (East)","location":"South Bend, IN","name":"John Nunemaker","friends_count":138,"profile_text_color":"666666","id":4243,"profile_background_image_url":"http://s.twimg.com/a/1256778767/images/themes/theme9/bg.gif","utc_offset":-18000},"in_reply_to_screen_name":null,"id":5272535583,"text":"Whoa. Webkit Nightly has some new inspector features: event listeners, cookies, css hex colors... http://rubyurl.com/hh5p"}]
View
1 test/fixtures/list_statuses_2_1.json
@@ -0,0 +1 @@
+[{"geo":null,"in_reply_to_user_id":null,"in_reply_to_status_id":null,"truncated":false,"favorited":false,"source":"<a href=\"http://www.atebits.com/\" rel=\"nofollow\">Tweetie</a>","created_at":"Thu Oct 29 17:35:07 +0000 2009","in_reply_to_screen_name":null,"user":{"profile_text_color":"666666","profile_image_url":"http://a3.twimg.com/profile_images/61024905/black250_normal.jpg","description":"I make things simple.","following":true,"statuses_count":6121,"profile_background_image_url":"http://s.twimg.com/a/1256597179/images/themes/theme9/bg.gif","profile_link_color":"2FC2EF","screen_name":"jnunemaker","geo_enabled":false,"profile_background_tile":false,"profile_background_color":"1A1B1F","url":"http://railstips.org/about","verified":false,"created_at":"Sun Aug 13 22:56:06 +0000 2006","profile_sidebar_fill_color":"252429","followers_count":1660,"protected":false,"friends_count":138,"profile_sidebar_border_color":"181A1E","location":"South Bend, IN","name":"John Nunemaker","id":4243,"notifications":false,"time_zone":"Indiana (East)","utc_offset":-18000,"favourites_count":115},"id":5264324712,"text":"I need some http://www.handerpants.com/ for night blogging. Haha."}]
View
21 test/twitter/base_test.rb
@@ -240,6 +240,27 @@ class BaseTest < Test::Unit::TestCase
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('/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('/pengwynn/lists/rubyists/statuses.json?page=1&per_page=1', 'list_statuses_1_1.json')
+ stub_get('/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
should "be able to view list members" do
stub_get('/pengwynn/rubyists/members.json', 'list_users.json')

0 comments on commit 591d31a

Please sign in to comment.
Something went wrong with that request. Please try again.