Skip to content

Commit

Permalink
Refactoring cursor parameter into a query for Base#lists
Browse files Browse the repository at this point in the history
  • Loading branch information
zmoazeni committed Apr 9, 2010
1 parent 52d52e0 commit d283cef
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/twitter/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
24 changes: 24 additions & 0 deletions test/twitter/base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit d283cef

Please sign in to comment.