Permalink
Browse files

Refactoring cursor parameter into a query for Base#lists

  • Loading branch information...
1 parent 52d52e0 commit d283cefdbcaeee6005b0ec747e8d6bded14911b2 @zmoazeni zmoazeni committed Apr 9, 2010
Showing with 30 additions and 6 deletions.
  1. +6 −6 lib/twitter/base.rb
  2. +24 −0 test/twitter/base_test.rb
View
12 lib/twitter/base.rb
@@ -243,14 +243,14 @@ def list_delete(list_owner_username, slug)
perform_delete("/#{API_VERSION}/#{list_owner_username}/lists/#{slug}.json")
end
- def lists(list_owner_username = nil, cursor = nil)
- if list_owner_username
- path = "/#{API_VERSION}/#{list_owner_username}/lists.json"
+ def lists(list_owner_username = nil, query = {})
+ path = case list_owner_username
+ when nil, Hash
+ query = list_owner_username
+ "/#{API_VERSION}/lists.json"
else
- path = "/#{API_VERSION}/lists.json"
+ "/#{API_VERSION}/#{list_owner_username}/lists.json"
end
- query = {}
- query[:cursor] = cursor if cursor
perform_get(path, :query => query)
end
View
24 test/twitter/base_test.rb
@@ -257,6 +257,30 @@ class BaseTest < Test::Unit::TestCase
lists.first.name.should == 'Rubyists'
lists.first.slug.should == 'rubyists'
end
+
+ should "be able to view the user owned lists without passing the username" do
+ stub_get('/1/lists.json', 'lists.json')
+ lists = @twitter.lists().lists
+ lists.size.should == 1
+ lists.first.name.should == 'Rubyists'
+ lists.first.slug.should == 'rubyists'
+ end
+
+ should "be able to view lists for the authenticated user by passing in a cursor" do
+ stub_get('/1/pengwynn/lists.json?cursor=-1', 'lists.json')
+ lists = @twitter.lists('pengwynn', :cursor => -1).lists
+ lists.size.should == 1
+ lists.first.name.should == 'Rubyists'
+ lists.first.slug.should == 'rubyists'
+ end
+
+ should "be able to view the user owned lists without passing the username and passing in a cursor" do
+ stub_get('/1/lists.json?cursor=-1', 'lists.json')
+ lists = @twitter.lists(:cursor => -1).lists
+ lists.size.should == 1
+ lists.first.name.should == 'Rubyists'
+ lists.first.slug.should == 'rubyists'
+ end
should "be able to view list details" do
stub_get('/1/pengwynn/lists/rubyists.json', 'list.json')

0 comments on commit d283cef

Please sign in to comment.