Skip to content

Commit

Permalink
Unathenticated list timeline method added
Browse files Browse the repository at this point in the history
  • Loading branch information
spastorino committed Jan 29, 2010
1 parent 358ff33 commit aed3a29
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/twitter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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__))
Expand Down
33 changes: 33 additions & 0 deletions test/twitter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.