Skip to content

Commit

Permalink
added pagination support to base.list_timeline along with correspondi…
Browse files Browse the repository at this point in the history
…ng tests
  • Loading branch information
Chen authored and Chen committed Dec 16, 2009
1 parent 36b07be commit 591d31a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/twitter/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/list_statuses_1_1.json
Original file line number Diff line number Diff line change
@@ -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"}]
1 change: 1 addition & 0 deletions test/fixtures/list_statuses_2_1.json
Original file line number Diff line number Diff line change
@@ -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."}]
21 changes: 21 additions & 0 deletions test/twitter/base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 591d31a

Please sign in to comment.