Skip to content
Browse files

Fix max collect id when API returns less results than expected

The Twitter API returns inconsistent count of tweets and often
the API response includes less tweets than the requested count.

This patch solves the issue by querying the Twitter API in a
loop until the expected number of results is reached.
  • Loading branch information...
1 parent 2bc8242 commit 929dd963df5957c8b2e5654358f802fa1044af9a @jphpsf committed May 10, 2012
Showing with 479 additions and 37 deletions.
  1. +3 −2 lib/t/collectable.rb
  2. +139 −27 spec/cli_spec.rb
  3. +111 −1 spec/fixtures/search.json
  4. +180 −0 spec/fixtures/statuses.json
  5. +23 −4 spec/list_spec.rb
  6. +23 −3 spec/search_spec.rb
View
5 lib/t/collectable.rb
@@ -33,8 +33,9 @@ def collect_with_number(number, key, &block)
opts[:max_id] = max_id unless max_id.nil?
opts[key] = number unless number >= MAX_NUM_RESULTS
if number > 0
- number -= MAX_NUM_RESULTS
- yield opts
+ statuses = yield opts
+ number -= statuses.length
+ statuses
end
end.flatten.compact
end
View
166 spec/cli_spec.rb
@@ -113,6 +113,9 @@
stub_get("/1/direct_messages.json").
with(:query => {:count => "20"}).
to_return(:body => fixture("direct_messages.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ stub_get("/1/direct_messages.json").
+ with(:query => {:count => "10", "max_id"=>"1624782205"}).
+ to_return(:body => fixture("empty_array.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "should request the correct resource" do
@cli.direct_messages
@@ -186,8 +189,13 @@
with(:query => {:count => "200"}).
to_return(:body => fixture("direct_messages.json"), :headers => {:content_type => "application/json; charset=utf-8"})
stub_get("/1/direct_messages.json").
- with(:query => {:count => "145", :max_id => "1624782205"}).
- to_return(:body => fixture("empty_array.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ with(:query => {:count => "200", :max_id => "1624782205"}).
+ to_return(:body => fixture("direct_messages.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ (5..195).step(10).to_a.reverse.each do |count|
+ stub_get("/1/direct_messages.json").
+ with(:query => {:count => count, :max_id => "1624782205"}).
+ to_return(:body => fixture("direct_messages.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ end
end
it "should limit the number of results to 1" do
@cli.options = @cli.options.merge("number" => 1)
@@ -203,8 +211,13 @@
with(:query => {:count => "200"}).
should have_been_made
a_get("/1/direct_messages.json").
- with(:query => {:count => "145", :max_id => "1624782205"}).
- should have_been_made
+ with(:query => {:count => "200", :max_id => "1624782205"}).
+ should have_been_made.times(14)
+ (5..195).step(10).to_a.reverse.each do |count|
+ a_get("/1/direct_messages.json").
+ with(:query => {:count => count, :max_id => "1624782205"}).
+ should have_been_made
+ end
end
end
context "--reverse" do
@@ -234,6 +247,9 @@
stub_get("/1/direct_messages/sent.json").
with(:query => {:count => "20"}).
to_return(:body => fixture("direct_messages.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ stub_get("/1/direct_messages/sent.json").
+ with(:query => {:count => "10", "max_id"=>"1624782205"}).
+ to_return(:body => fixture("empty_array.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "should request the correct resource" do
@cli.direct_messages_sent
@@ -307,8 +323,13 @@
with(:query => {:count => "200"}).
to_return(:body => fixture("direct_messages.json"), :headers => {:content_type => "application/json; charset=utf-8"})
stub_get("/1/direct_messages/sent.json").
- with(:query => {:count => "145", :max_id => "1624782205"}).
+ with(:query => {:count => "200", :max_id => "1624782205"}).
to_return(:body => fixture("direct_messages.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ (5..195).step(10).to_a.reverse.each do |count|
+ stub_get("/1/direct_messages/sent.json").
+ with(:query => {:count => count, :max_id => "1624782205"}).
+ to_return(:body => fixture("direct_messages.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ end
end
it "should limit the number of results 1" do
@cli.options = @cli.options.merge("number" => 1)
@@ -324,8 +345,13 @@
with(:query => {:count => "200"}).
should have_been_made
a_get("/1/direct_messages/sent.json").
- with(:query => {:count => "145", :max_id => "1624782205"}).
- should have_been_made
+ with(:query => {:count => "200", :max_id => "1624782205"}).
+ should have_been_made.times(14)
+ (5..195).step(10).to_a.reverse.each do |count|
+ a_get("/1/direct_messages/sent.json").
+ with(:query => {:count => count, :max_id => "1624782205"}).
+ should have_been_made
+ end
end
end
context "--reverse" do
@@ -771,6 +797,9 @@
@cli.favorites
$stdout.string.should == <<-eos
ID,Posted at,Screen name,Text
+194548141663027221,2011-04-23 22:08:32 +0000,ryanbigg,"Things that have made my life better, in order of greatness: GitHub, Travis CI, the element Oxygen."
+194563027248121416,2011-04-23 22:08:11 +0000,sfbike,"Bike to Work Counts in: 73% of morning Market traffic was bikes! 1,031 bikers counted in 1 hour--that's 17 per minute. Way to roll, SF!"
+194548120271416632,2011-04-23 22:07:51 +0000,levie,"I know you're as rare as leprechauns, but if you're an amazing designer then Box wants to hire you. Email recruiting@box.com"
194548121416630272,2011-04-23 22:07:41 +0000,natevillegas,RT @gelobautista #riordan RT @WilI_Smith: Yesterday is history. Tomorrow is a mystery. Today is a gift. That's why it's called the present.
194547993607806976,2011-04-23 22:07:10 +0000,TD,@kelseysilver how long will you be in town?
194547987593183233,2011-04-23 22:07:09 +0000,rusashka,@maciej hahaha :) @gpena together we're going to cover all core 28 languages!
@@ -799,6 +828,9 @@
@cli.favorites
$stdout.string.should == <<-eos
ID Posted at Screen name Text
+194548141663027221 Apr 23 2011 @ryanbigg Things that have made my lif...
+194563027248121416 Apr 23 2011 @sfbike Bike to Work Counts in: 73% ...
+194548120271416632 Apr 23 2011 @levie I know you're as rare as lep...
194548121416630272 Apr 23 2011 @natevillegas RT @gelobautista #riordan RT...
194547993607806976 Apr 23 2011 @TD @kelseysilver how long will ...
194547987593183233 Apr 23 2011 @rusashka @maciej hahaha :) @gpena tog...
@@ -843,6 +875,9 @@
194547987593183233 Apr 23 2011 @rusashka @maciej hahaha :) @gpena tog...
194547993607806976 Apr 23 2011 @TD @kelseysilver how long will ...
194548121416630272 Apr 23 2011 @natevillegas RT @gelobautista #riordan RT...
+194548120271416632 Apr 23 2011 @levie I know you're as rare as lep...
+194563027248121416 Apr 23 2011 @sfbike Bike to Work Counts in: 73% ...
+194548141663027221 Apr 23 2011 @ryanbigg Things that have made my lif...
eos
end
end
@@ -856,8 +891,13 @@
with(:query => {:count => "200"}).
to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
stub_get("/1/favorites.json").
- with(:query => {:count => "145", :max_id => "194546264212385792"}).
- to_return(:body => fixture("empty_array.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ with(:query => {:count => "200", :max_id => "194546264212385792"}).
+ to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ (5..185).step(20).to_a.reverse.each do |count|
+ stub_get("/1/favorites.json").
+ with(:query => {:count => count, :max_id => "194546264212385792"}).
+ to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ end
end
it "should limit the number of results to 1" do
@cli.options = @cli.options.merge("number" => 1)
@@ -873,8 +913,13 @@
with(:query => {:count => "200"}).
should have_been_made
a_get("/1/favorites.json").
- with(:query => {:count => "145", :max_id => "194546264212385792"}).
- should have_been_made
+ with(:query => {:count => "200", :max_id => "194546264212385792"}).
+ should have_been_made.times(7)
+ (5..185).step(20).to_a.reverse.each do |count|
+ a_get("/1/favorites.json").
+ with(:query => {:count => count, :max_id => "194546264212385792"}).
+ should have_been_made
+ end
end
end
context "with a user passed" do
@@ -1767,6 +1812,9 @@
@cli.mentions
$stdout.string.should == <<-eos
ID,Posted at,Screen name,Text
+194548141663027221,2011-04-23 22:08:32 +0000,ryanbigg,"Things that have made my life better, in order of greatness: GitHub, Travis CI, the element Oxygen."
+194563027248121416,2011-04-23 22:08:11 +0000,sfbike,"Bike to Work Counts in: 73% of morning Market traffic was bikes! 1,031 bikers counted in 1 hour--that's 17 per minute. Way to roll, SF!"
+194548120271416632,2011-04-23 22:07:51 +0000,levie,"I know you're as rare as leprechauns, but if you're an amazing designer then Box wants to hire you. Email recruiting@box.com"
194548121416630272,2011-04-23 22:07:41 +0000,natevillegas,RT @gelobautista #riordan RT @WilI_Smith: Yesterday is history. Tomorrow is a mystery. Today is a gift. That's why it's called the present.
194547993607806976,2011-04-23 22:07:10 +0000,TD,@kelseysilver how long will you be in town?
194547987593183233,2011-04-23 22:07:09 +0000,rusashka,@maciej hahaha :) @gpena together we're going to cover all core 28 languages!
@@ -1795,6 +1843,9 @@
@cli.mentions
$stdout.string.should == <<-eos
ID Posted at Screen name Text
+194548141663027221 Apr 23 2011 @ryanbigg Things that have made my lif...
+194563027248121416 Apr 23 2011 @sfbike Bike to Work Counts in: 73% ...
+194548120271416632 Apr 23 2011 @levie I know you're as rare as lep...
194548121416630272 Apr 23 2011 @natevillegas RT @gelobautista #riordan RT...
194547993607806976 Apr 23 2011 @TD @kelseysilver how long will ...
194547987593183233 Apr 23 2011 @rusashka @maciej hahaha :) @gpena tog...
@@ -1839,6 +1890,9 @@
194547987593183233 Apr 23 2011 @rusashka @maciej hahaha :) @gpena tog...
194547993607806976 Apr 23 2011 @TD @kelseysilver how long will ...
194548121416630272 Apr 23 2011 @natevillegas RT @gelobautista #riordan RT...
+194548120271416632 Apr 23 2011 @levie I know you're as rare as lep...
+194563027248121416 Apr 23 2011 @sfbike Bike to Work Counts in: 73% ...
+194548141663027221 Apr 23 2011 @ryanbigg Things that have made my lif...
eos
end
end
@@ -1852,8 +1906,13 @@
with(:query => {:count => "200"}).
to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
stub_get("/1/statuses/mentions.json").
- with(:query => {:count => "145", :max_id => "194546264212385792"}).
- to_return(:body => fixture("empty_array.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ with(:query => {:count => "200", :max_id => "194546264212385792"}).
+ to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ (5..185).step(20).to_a.reverse.each do |count|
+ stub_get("/1/statuses/mentions.json").
+ with(:query => {:count => count, :max_id => "194546264212385792"}).
+ to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ end
end
it "should limit the number of results to 1" do
@cli.options = @cli.options.merge("number" => 1)
@@ -1869,8 +1928,13 @@
with(:query => {:count => "200"}).
should have_been_made
a_get("/1/statuses/mentions.json").
- with(:query => {:count => "145", :max_id => "194546264212385792"}).
- should have_been_made
+ with(:query => {:count => "200", :max_id => "194546264212385792"}).
+ should have_been_made.times(7)
+ (5..185).step(20).to_a.reverse.each do |count|
+ a_get("/1/statuses/mentions.json").
+ with(:query => {:count => count, :max_id => "194546264212385792"}).
+ should have_been_made
+ end
end
end
end
@@ -2084,6 +2148,9 @@
@cli.retweets
$stdout.string.should == <<-eos
ID,Posted at,Screen name,Text
+194548141663027221,2011-04-23 22:08:32 +0000,ryanbigg,"Things that have made my life better, in order of greatness: GitHub, Travis CI, the element Oxygen."
+194563027248121416,2011-04-23 22:08:11 +0000,sfbike,"Bike to Work Counts in: 73% of morning Market traffic was bikes! 1,031 bikers counted in 1 hour--that's 17 per minute. Way to roll, SF!"
+194548120271416632,2011-04-23 22:07:51 +0000,levie,"I know you're as rare as leprechauns, but if you're an amazing designer then Box wants to hire you. Email recruiting@box.com"
194548121416630272,2011-04-23 22:07:41 +0000,natevillegas,RT @gelobautista #riordan RT @WilI_Smith: Yesterday is history. Tomorrow is a mystery. Today is a gift. That's why it's called the present.
194547993607806976,2011-04-23 22:07:10 +0000,TD,@kelseysilver how long will you be in town?
194547987593183233,2011-04-23 22:07:09 +0000,rusashka,@maciej hahaha :) @gpena together we're going to cover all core 28 languages!
@@ -2112,6 +2179,9 @@
@cli.retweets
$stdout.string.should == <<-eos
ID Posted at Screen name Text
+194548141663027221 Apr 23 2011 @ryanbigg Things that have made my lif...
+194563027248121416 Apr 23 2011 @sfbike Bike to Work Counts in: 73% ...
+194548120271416632 Apr 23 2011 @levie I know you're as rare as lep...
194548121416630272 Apr 23 2011 @natevillegas RT @gelobautista #riordan RT...
194547993607806976 Apr 23 2011 @TD @kelseysilver how long will ...
194547987593183233 Apr 23 2011 @rusashka @maciej hahaha :) @gpena tog...
@@ -2156,6 +2226,9 @@
194547987593183233 Apr 23 2011 @rusashka @maciej hahaha :) @gpena tog...
194547993607806976 Apr 23 2011 @TD @kelseysilver how long will ...
194548121416630272 Apr 23 2011 @natevillegas RT @gelobautista #riordan RT...
+194548120271416632 Apr 23 2011 @levie I know you're as rare as lep...
+194563027248121416 Apr 23 2011 @sfbike Bike to Work Counts in: 73% ...
+194548141663027221 Apr 23 2011 @ryanbigg Things that have made my lif...
eos
end
end
@@ -2169,8 +2242,13 @@
with(:query => {:count => "200"}).
to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
stub_get("/1/statuses/retweeted_by_me.json").
- with(:query => {:count => "145", :max_id => "194546264212385792"}).
- to_return(:body => fixture("empty_array.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ with(:query => {:count => "200", :max_id => "194546264212385792"}).
+ to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ (5..185).step(20).to_a.reverse.each do |count|
+ stub_get("/1/statuses/retweeted_by_me.json").
+ with(:query => {:count => count, :max_id => "194546264212385792"}).
+ to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ end
end
it "should limit the number of results to 1" do
@cli.options = @cli.options.merge("number" => 1)
@@ -2186,8 +2264,13 @@
with(:query => {:count => "200"}).
should have_been_made
a_get("/1/statuses/retweeted_by_me.json").
- with(:query => {:count => "145", :max_id => "194546264212385792"}).
- should have_been_made
+ with(:query => {:count => "200", :max_id => "194546264212385792"}).
+ should have_been_made.times(7)
+ (5..185).step(20).to_a.reverse.each do |count|
+ a_get("/1/statuses/retweeted_by_me.json").
+ with(:query => {:count => count, :max_id => "194546264212385792"}).
+ should have_been_made
+ end
end
end
context "with a user passed" do
@@ -2560,6 +2643,9 @@
@cli.timeline
$stdout.string.should == <<-eos
ID,Posted at,Screen name,Text
+194548141663027221,2011-04-23 22:08:32 +0000,ryanbigg,"Things that have made my life better, in order of greatness: GitHub, Travis CI, the element Oxygen."
+194563027248121416,2011-04-23 22:08:11 +0000,sfbike,"Bike to Work Counts in: 73% of morning Market traffic was bikes! 1,031 bikers counted in 1 hour--that's 17 per minute. Way to roll, SF!"
+194548120271416632,2011-04-23 22:07:51 +0000,levie,"I know you're as rare as leprechauns, but if you're an amazing designer then Box wants to hire you. Email recruiting@box.com"
194548121416630272,2011-04-23 22:07:41 +0000,natevillegas,RT @gelobautista #riordan RT @WilI_Smith: Yesterday is history. Tomorrow is a mystery. Today is a gift. That's why it's called the present.
194547993607806976,2011-04-23 22:07:10 +0000,TD,@kelseysilver how long will you be in town?
194547987593183233,2011-04-23 22:07:09 +0000,rusashka,@maciej hahaha :) @gpena together we're going to cover all core 28 languages!
@@ -2588,6 +2674,9 @@
@cli.timeline
$stdout.string.should == <<-eos
ID Posted at Screen name Text
+194548141663027221 Apr 23 2011 @ryanbigg Things that have made my lif...
+194563027248121416 Apr 23 2011 @sfbike Bike to Work Counts in: 73% ...
+194548120271416632 Apr 23 2011 @levie I know you're as rare as lep...
194548121416630272 Apr 23 2011 @natevillegas RT @gelobautista #riordan RT...
194547993607806976 Apr 23 2011 @TD @kelseysilver how long will ...
194547987593183233 Apr 23 2011 @rusashka @maciej hahaha :) @gpena tog...
@@ -2632,6 +2721,9 @@
194547987593183233 Apr 23 2011 @rusashka @maciej hahaha :) @gpena tog...
194547993607806976 Apr 23 2011 @TD @kelseysilver how long will ...
194548121416630272 Apr 23 2011 @natevillegas RT @gelobautista #riordan RT...
+194548120271416632 Apr 23 2011 @levie I know you're as rare as lep...
+194563027248121416 Apr 23 2011 @sfbike Bike to Work Counts in: 73% ...
+194548141663027221 Apr 23 2011 @ryanbigg Things that have made my lif...
eos
end
end
@@ -2645,8 +2737,13 @@
with(:query => {:count => "200"}).
to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
stub_get("/1/statuses/home_timeline.json").
- with(:query => {:count => "145", :max_id => "194546264212385792"}).
- to_return(:body => fixture("empty_array.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ with(:query => {:count => "200", :max_id => "194546264212385792"}).
+ to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ (5..185).step(20).to_a.reverse.each do |count|
+ stub_get("/1/statuses/home_timeline.json").
+ with(:query => {:count => count, :max_id => "194546264212385792"}).
+ to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ end
end
it "should limit the number of results to 1" do
@cli.options = @cli.options.merge("number" => 1)
@@ -2662,8 +2759,13 @@
with(:query => {:count => "200"}).
should have_been_made
a_get("/1/statuses/home_timeline.json").
- with(:query => {:count => "145", :max_id => "194546264212385792"}).
- should have_been_made
+ with(:query => {:count => "200", :max_id => "194546264212385792"}).
+ should have_been_made.times(7)
+ (5..185).step(20).to_a.reverse.each do |count|
+ a_get("/1/statuses/home_timeline.json").
+ with(:query => {:count => count, :max_id => "194546264212385792"}).
+ should have_been_made
+ end
end
end
context "with a user passed" do
@@ -2701,8 +2803,13 @@
with(:query => {:count => "200", :screen_name => "sferik"}).
to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
stub_get("/1/statuses/user_timeline.json").
- with(:query => {:count => "145", :screen_name => "sferik", :max_id => "194546264212385792"}).
- to_return(:body => fixture("empty_array.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ with(:query => {:count => "200", :screen_name => "sferik", :max_id => "194546264212385792"}).
+ to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ (5..185).step(20).to_a.reverse.each do |count|
+ stub_get("/1/statuses/user_timeline.json").
+ with(:query => {:count => count, :screen_name => "sferik", :max_id => "194546264212385792"}).
+ to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ end
end
it "should limit the number of results to 1" do
@cli.options = @cli.options.merge("number" => 1)
@@ -2718,8 +2825,13 @@
with(:query => {:count => "200", :screen_name => "sferik"}).
should have_been_made
a_get("/1/statuses/user_timeline.json").
- with(:query => {:count => "145", :screen_name => "sferik", :max_id => "194546264212385792"}).
- should have_been_made
+ with(:query => {:count => "200", :screen_name => "sferik", :max_id => "194546264212385792"}).
+ should have_been_made.times(7)
+ (5..185).step(20).to_a.reverse.each do |count|
+ a_get("/1/statuses/user_timeline.json").
+ with(:query => {:count => count, :screen_name => "sferik", :max_id => "194546264212385792"}).
+ should have_been_made
+ end
end
end
end
View
112 spec/fixtures/search.json
@@ -9,6 +9,116 @@
"results": [
{
"created_at": "Mon, 23 Apr 2011 20:20:57 +0000",
+ "from_user": "Somedude",
+ "from_user_id": 818993897,
+ "from_user_id_str": "818993897",
+ "from_user_name": "Random Dude",
+ "geo": null,
+ "id": 194521323202624150,
+ "id_str": "194521323202624150",
+ "iso_language_code": "en",
+ "metadata": {
+ "result_type": "recent"
+ },
+ "profile_image_url": "http://a0.twimg.com/profile_images/1014656526/pic.jpg",
+ "profile_image_url_https": "https://si0.twimg.com/profile_images/1014656526/pic.jpg",
+ "source": "&lt;a href=&quot;http://twitter.com/&quot;&gt;web&lt;/a&gt;",
+ "text": "Gotta get right with twitter",
+ "to_user": null,
+ "to_user_id": null,
+ "to_user_id_str": null,
+ "to_user_name": null
+ },
+ {
+ "created_at": "Mon, 23 Apr 2011 20:20:57 +0000",
+ "from_user": "TestMan",
+ "from_user_id": 32702507980,
+ "from_user_id_str": "32702507980",
+ "from_user_name": "Test Account",
+ "geo": null,
+ "id": 194526951936212623,
+ "id_str": "194526951936212623",
+ "iso_language_code": "en",
+ "metadata": {
+ "result_type": "recent"
+ },
+ "profile_image_url": "http://a0.twimg.com/profile_images/2147508883/IMG-20120404-WA003_normal.jpg",
+ "profile_image_url_https": "https://si0.twimg.com/profile_images/2147508883/IMG-20120404-WA003_normal.jpg",
+ "source": "&lt;a href=&quot;http://blackberry.com/twitter&quot; rel=&quot;nofollow&quot;&gt;Twitter for BlackBerry®&lt;/a&gt;",
+ "text": "Twitter to Facebook test",
+ "to_user": null,
+ "to_user_id": null,
+ "to_user_id_str": null,
+ "to_user_name": null
+ },
+ {
+ "created_at": "Mon, 23 Apr 2011 20:20:57 +0000",
+ "from_user": "Jena_Jones",
+ "from_user_id": 13938181651,
+ "from_user_id_str": "13938181651",
+ "from_user_name": "Jena Jones",
+ "geo": null,
+ "id": 194521346690562622,
+ "id_str": "194521346690562622",
+ "iso_language_code": "en",
+ "metadata": {
+ "result_type": "recent"
+ },
+ "profile_image_url": "http://a0.twimg.com/profile_images/2156571407/543631_337343819653633_100001340549098_850013_1999940127_n_normal.jpg",
+ "profile_image_url_https": "https://si0.twimg.com/profile_images/2156571407/543631_337343819653633_100001340549098_850013_1999940127_n_normal.jpg",
+ "source": "&lt;a href=&quot;http://mobile.twitter.com&quot; rel=&quot;nofollow&quot;&gt;Mobile Web&lt;/a&gt;",
+ "text": "test my new twitter..... :)",
+ "to_user": null,
+ "to_user_id": null,
+ "to_user_id_str": null,
+ "to_user_name": null
+ },
+ {
+ "created_at": "Mon, 23 Apr 2011 20:20:57 +0000",
+ "from_user": "misterpic",
+ "from_user_id": 259342250,
+ "from_user_id_str": "259342250",
+ "from_user_name": "mister pic!",
+ "geo": null,
+ "id": 194521262134160820,
+ "id_str": "194521262134160820",
+ "iso_language_code": "en",
+ "metadata": {
+ "result_type": "recent"
+ },
+ "profile_image_url": "http://a0.twimg.com/profile_images/2159952653/P2191655_normal.JPG",
+ "profile_image_url_https": "https://si0.twimg.com/profile_images/2159952653/P2191655_normal.JPG",
+ "source": "&lt;a href=&quot;http://twitter.com/#!/download/iphone&quot; rel=&quot;nofollow&quot;&gt;Twitter for iPhone&lt;/a&gt;",
+ "text": "Wallah there should be a test before you can get a twitter account some people are so dumb... better",
+ "to_user": null,
+ "to_user_id": null,
+ "to_user_id_str": null,
+ "to_user_name": null
+ },
+ {
+ "created_at": "Mon, 23 Apr 2011 20:20:57 +0000",
+ "from_user": "RRabbit",
+ "from_user_id": 91022555146,
+ "from_user_id_str": "91022555146",
+ "from_user_name": "Rogger Rabbit",
+ "geo": null,
+ "id": 194521016652621340,
+ "id_str": "194521016652621340",
+ "iso_language_code": "en",
+ "metadata": {
+ "result_type": "recent"
+ },
+ "profile_image_url": "http://a0.twimg.com/profile_images/1663790229/390753_10150394068222898_738242897_8656853_1501249832_n_1__normal.jpg",
+ "profile_image_url_https": "https://si0.twimg.com/profile_images/1663790229/390753_10150394068222898_738242897_8656853_1501249832_n_1__normal.jpg",
+ "source": "&lt;a href=&quot;http://twitter.com/#!/download/iphone&quot; rel=&quot;nofollow&quot;&gt;Twitter for iPhone&lt;/a&gt;",
+ "text": "Twitter is kinda fun... Kinda!",
+ "to_user": null,
+ "to_user_id": null,
+ "to_user_id_str": null,
+ "to_user_name": null
+ },
+ {
+ "created_at": "Mon, 23 Apr 2011 20:20:57 +0000",
"from_user": "JessRoveel",
"from_user_id": 99818387,
"from_user_id_str": "99818387",
@@ -340,7 +450,7 @@
"to_user_name": null
}
],
- "results_per_page": 15,
+ "results_per_page": 20,
"since_id": 0,
"since_id_str": "0"
}
View
180 spec/fixtures/statuses.json
@@ -6,6 +6,186 @@
"contributors": null,
"in_reply_to_screen_name": null,
"truncated": false,
+ "id_str": "194548141663027221",
+ "coordinates": null,
+ "in_reply_to_user_id": null,
+ "place": null,
+ "user": {
+ "id": 14506011,
+ "followers_count": 2588,
+ "profile_background_color": "5D8A8C",
+ "url": "http://www.ryanbigg.com",
+ "created_at": "Thu Apr 24 03:23:53 +0000 2008",
+ "profile_background_image_url": "http://a0.twimg.com/profile_background_images/2503404/Untitled.jpg",
+ "listed_count": 250,
+ "lang": "en",
+ "profile_link_color": "000000",
+ "utc_offset": 36000,
+ "name": "Ryan Bigg",
+ "is_translator": false,
+ "location": "Melbourne, Australia",
+ "protected": false,
+ "profile_use_background_image": true,
+ "profile_image_url_https": "https://si0.twimg.com/profile_images/1500934941/superman_normal.png",
+ "time_zone": "Brisbane",
+ "profile_text_color": "000000",
+ "friends_count": 417,
+ "profile_background_image_url_https": "https://si0.twimg.com/profile_background_images/2503404/Untitled.jpg",
+ "default_profile_image": false,
+ "verified": false,
+ "profile_sidebar_border_color": "000000",
+ "favourites_count": 267,
+ "following": false,
+ "statuses_count": 33152,
+ "description": "Award winning super hero published author (Rails 3 in Action). Avid cyclist and hiker. Community manager for Spree Commerce. Views are my own, etc.",
+ "contributors_enabled": false,
+ "id_str": "14506011",
+ "geo_enabled": true,
+ "profile_background_tile": true,
+ "show_all_inline_media": true,
+ "profile_sidebar_border_color": "121212",
+ "follow_request_sent": false,
+ "screen_name": "ryanbigg",
+ "default_profile": false,
+ "profile_image_url": "http://a0.twimg.com/profile_images/1500934941/superman_normal.png",
+ "notifications": false
+ },
+ "retweet_count": 0,
+ "favorited": false,
+ "in_reply_to_status_id_str": null,
+ "source": "web",
+ "in_reply_to_user_id_str": null,
+ "id": 194548141663027221,
+ "created_at": "Mon Apr 23 22:08:32 +0000 2011",
+ "text": "Things that have made my life better, in order of greatness: GitHub, Travis CI, the element Oxygen."
+ },
+ {
+ "geo": null,
+ "retweeted": false,
+ "in_reply_to_status_id": null,
+ "contributors": null,
+ "in_reply_to_screen_name": null,
+ "truncated": false,
+ "id_str": "194548121416630272",
+ "coordinates": null,
+ "in_reply_to_user_id": null,
+ "place": null,
+ "user": {
+ "id": 20187443,
+ "followers_count": 8365,
+ "profile_background_color": "C0DEED",
+ "url": "http://sfbike.org",
+ "created_at": "Thu Feb 05 21:00:04 +0000 2009",
+ "profile_background_image_url": "http://a0.twimg.com/images/themes/theme1/bg.png",
+ "listed_count": 609,
+ "lang": "en",
+ "profile_link_color": "591828",
+ "utc_offset": -28800,
+ "name": "SF Bicycle Coalition",
+ "is_translator": false,
+ "location": "San Francisco",
+ "protected": false,
+ "profile_use_background_image": true,
+ "profile_image_url_https": "https://si0.twimg.com/profile_images/75810351/logo_normal.jpg",
+ "time_zone": "Pacific Time (US & Canada)",
+ "profile_text_color": "000000",
+ "friends_count": 1346,
+ "profile_background_image_url_https": "https://si0.twimg.com/images/themes/theme1/bg.png",
+ "default_profile_image": false,
+ "verified": false,
+ "profile_sidebar_border_color": "000000",
+ "favourites_count": 53,
+ "following": false,
+ "statuses_count": 3051,
+ "description": "Promoting the bicycle for everyday transportation",
+ "contributors_enabled": false,
+ "id_str": "20187443",
+ "geo_enabled": true,
+ "profile_background_tile": false,
+ "show_all_inline_media": true,
+ "profile_sidebar_fill_color": "f8f6f6",
+ "follow_request_sent": false,
+ "screen_name": "sfbike",
+ "default_profile": false,
+ "profile_image_url": "http://a0.twimg.com/profile_images/75810351/logo_normal.jpg",
+ "notifications": false
+ },
+ "retweet_count": 0,
+ "favorited": false,
+ "in_reply_to_status_id_str": null,
+ "source": "web",
+ "in_reply_to_user_id_str": null,
+ "id": 194563027248121416,
+ "created_at": "Mon Apr 23 22:08:11 +0000 2011",
+ "text": "Bike to Work Counts in: 73% of morning Market traffic was bikes! 1,031 bikers counted in 1 hour--that's 17 per minute. Way to roll, SF!"
+ },
+ {
+ "geo": null,
+ "retweeted": false,
+ "in_reply_to_status_id": null,
+ "contributors": null,
+ "in_reply_to_screen_name": null,
+ "truncated": false,
+ "id_str": "194548120271416632",
+ "coordinates": null,
+ "in_reply_to_user_id": null,
+ "place": null,
+ "user": {
+ "id": 914061,
+ "followers_count": 8943,
+ "profile_background_color": "FFFAFE",
+ "url": "http://www.box.com",
+ "created_at": "Sun Mar 11 09:25:44 +0000 2007",
+ "profile_background_image_url": "http://a0.twimg.com/profile_background_images/21668675/box_logo.png",
+ "listed_count": 291,
+ "lang": "en",
+ "profile_link_color": "0000FF",
+ "utc_offset": -28800,
+ "name": "Aaron Levie",
+ "is_translator": false,
+ "location": "Palo Alto",
+ "protected": false,
+ "profile_use_background_image": false,
+ "profile_image_url_https": "https://si0.twimg.com/profile_images/1626898956/twitter_normal.png",
+ "time_zone": "Pacific Time (US & Canada)",
+ "profile_text_color": "000000",
+ "friends_count": 486,
+ "profile_background_image_url_https": "https://si0.twimg.com/profile_background_images/21668675/box_logo.png",
+ "default_profile_image": false,
+ "verified": false,
+ "profile_sidebar_border_color": "87BC44",
+ "favourites_count": 439,
+ "following": false,
+ "statuses_count": 1301,
+ "description": "Lead Magician (and CEO) at Box; I don't fully endorse anything I say below. Go ☁",
+ "contributors_enabled": false,
+ "id_str": "914061",
+ "geo_enabled": true,
+ "profile_background_tile": true,
+ "show_all_inline_media": true,
+ "profile_sidebar_fill_color": "E0FF92",
+ "follow_request_sent": false,
+ "screen_name": "levie",
+ "default_profile": false,
+ "profile_image_url": "http://a0.twimg.com/profile_images/1626898956/twitter_normal.png",
+ "notifications": false
+ },
+ "retweet_count": 0,
+ "favorited": false,
+ "in_reply_to_status_id_str": null,
+ "source": "web",
+ "in_reply_to_user_id_str": null,
+ "id": 194548120271416632,
+ "created_at": "Mon Apr 23 22:07:51 +0000 2011",
+ "text": "I know you're as rare as leprechauns, but if you're an amazing designer then Box wants to hire you. Email recruiting@box.com"
+ },
+ {
+ "geo": null,
+ "retweeted": false,
+ "in_reply_to_status_id": null,
+ "contributors": null,
+ "in_reply_to_screen_name": null,
+ "truncated": false,
"id_str": "194548121416630272",
"coordinates": null,
"in_reply_to_user_id": null,
View
27 spec/list_spec.rb
@@ -382,6 +382,9 @@
@list.timeline("presidents")
$stdout.string.should == <<-eos
ID,Posted at,Screen name,Text
+194548141663027221,2011-04-23 22:08:32 +0000,ryanbigg,"Things that have made my life better, in order of greatness: GitHub, Travis CI, the element Oxygen."
+194563027248121416,2011-04-23 22:08:11 +0000,sfbike,"Bike to Work Counts in: 73% of morning Market traffic was bikes! 1,031 bikers counted in 1 hour--that's 17 per minute. Way to roll, SF!"
+194548120271416632,2011-04-23 22:07:51 +0000,levie,"I know you're as rare as leprechauns, but if you're an amazing designer then Box wants to hire you. Email recruiting@box.com"
194548121416630272,2011-04-23 22:07:41 +0000,natevillegas,RT @gelobautista #riordan RT @WilI_Smith: Yesterday is history. Tomorrow is a mystery. Today is a gift. That's why it's called the present.
194547993607806976,2011-04-23 22:07:10 +0000,TD,@kelseysilver how long will you be in town?
194547987593183233,2011-04-23 22:07:09 +0000,rusashka,@maciej hahaha :) @gpena together we're going to cover all core 28 languages!
@@ -410,6 +413,9 @@
@list.timeline("presidents")
$stdout.string.should == <<-eos
ID Posted at Screen name Text
+194548141663027221 Apr 23 2011 @ryanbigg Things that have made my lif...
+194563027248121416 Apr 23 2011 @sfbike Bike to Work Counts in: 73% ...
+194548120271416632 Apr 23 2011 @levie I know you're as rare as lep...
194548121416630272 Apr 23 2011 @natevillegas RT @gelobautista #riordan RT...
194547993607806976 Apr 23 2011 @TD @kelseysilver how long will ...
194547987593183233 Apr 23 2011 @rusashka @maciej hahaha :) @gpena tog...
@@ -454,6 +460,9 @@
194547987593183233 Apr 23 2011 @rusashka @maciej hahaha :) @gpena tog...
194547993607806976 Apr 23 2011 @TD @kelseysilver how long will ...
194548121416630272 Apr 23 2011 @natevillegas RT @gelobautista #riordan RT...
+194548120271416632 Apr 23 2011 @levie I know you're as rare as lep...
+194563027248121416 Apr 23 2011 @sfbike Bike to Work Counts in: 73% ...
+194548141663027221 Apr 23 2011 @ryanbigg Things that have made my lif...
eos
end
end
@@ -467,8 +476,13 @@
with(:query => {:owner_screen_name => "testcli", :per_page => "200", :slug => "presidents"}).
to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
stub_get("/1/lists/statuses.json").
- with(:query => {:owner_screen_name => "testcli", :per_page => "145", :max_id => "194546264212385792", :slug => "presidents"}).
- to_return(:body => fixture("empty_array.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ with(:query => {:owner_screen_name => "testcli", :per_page => "200", :max_id => "194546264212385792", :slug => "presidents"}).
+ to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ (5..185).step(20).to_a.reverse.each do |count|
+ stub_get("/1/lists/statuses.json").
+ with(:query => {:owner_screen_name => "testcli", :per_page => count, :max_id => "194546264212385792", :slug => "presidents"}).
+ to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ end
end
it "should limit the number of results to 1" do
@list.options = @list.options.merge("number" => 1)
@@ -484,8 +498,13 @@
with(:query => {:owner_screen_name => "testcli", :per_page => "200", :slug => "presidents"}).
should have_been_made
a_get("/1/lists/statuses.json").
- with(:query => {:owner_screen_name => "testcli", :per_page => "145", :max_id => "194546264212385792", :slug => "presidents"}).
- should have_been_made
+ with(:query => {:owner_screen_name => "testcli", :per_page => "200", :max_id => "194546264212385792", :slug => "presidents"}).
+ should have_been_made.times(7)
+ (5..185).step(20).to_a.reverse.each do |count|
+ a_get("/1/lists/statuses.json").
+ with(:query => {:owner_screen_name => "testcli", :per_page => count, :max_id => "194546264212385792", :slug => "presidents"}).
+ should have_been_made
+ end
end
end
context "with a user passed" do
View
26 spec/search_spec.rb
@@ -53,6 +53,11 @@
@search.all("twitter")
$stdout.string.should == <<-eos
ID,Posted at,Screen name,Text
+194521323202624150,2011-04-23 20:20:57 +0000,Somedude,Gotta get right with twitter
+194526951936212623,2011-04-23 20:20:57 +0000,TestMan,Twitter to Facebook test
+194521346690562622,2011-04-23 20:20:57 +0000,Jena_Jones,test my new twitter..... :)
+194521262134160820,2011-04-23 20:20:57 +0000,misterpic,Wallah there should be a test before you can get a twitter account some people are so dumb... better
+194521016652621340,2011-04-23 20:20:57 +0000,RRabbit,Twitter is kinda fun... Kinda!
194521262415032320,2011-04-23 20:20:57 +0000,JessRoveel,Pondre lo mas importante de Hamlet en Twitter para recordarlo mejor :D
194521262326951936,2011-04-23 20:20:57 +0000,lauravgeest,Twitter doet het al 7 uur niet meer
194521262234669056,2011-04-23 20:20:57 +0000,Jenny_Bearx333,"I keep thinking that twitter is @instagram , and therefore double tap all the pics I like... #NotWorking"
@@ -83,6 +88,11 @@
@search.all("twitter")
$stdout.string.should == <<-eos
ID Posted at Screen name Text
+194521323202624150 Apr 23 2011 @Somedude Gotta get right with twitter
+194526951936212623 Apr 23 2011 @TestMan Twitter to Facebook test
+194521346690562622 Apr 23 2011 @Jena_Jones test my new twitter..... :)
+194521262134160820 Apr 23 2011 @misterpic Wallah there should be a ...
+194521016652621340 Apr 23 2011 @RRabbit Twitter is kinda fun... K...
194521262415032320 Apr 23 2011 @JessRoveel Pondre lo mas importante ...
194521262326951936 Apr 23 2011 @lauravgeest Twitter doet het al 7 uur...
194521262234669056 Apr 23 2011 @Jenny_Bearx333 I keep thinking that twit...
@@ -110,8 +120,13 @@
with(:query => {:q => "twitter", :rpp => "200"}).
to_return(:body => fixture("search.json"), :headers => {:content_type => "application/json; charset=utf-8"})
stub_request(:get, "https://search.twitter.com/search.json").
- with(:query => {:q => "twitter", :rpp => "145", :max_id => "194521261307727871"}).
+ with(:query => {:q => "twitter", :rpp => "200", :max_id => "194521261307727871"}).
to_return(:body => fixture("search.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ (5..185).step(20).to_a.reverse.each do |count|
+ stub_request(:get, "https://search.twitter.com/search.json").
+ with(:query => {:q => "twitter", :rpp => count, :max_id => "194521261307727871"}).
+ to_return(:body => fixture("search.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ end
end
it "should limit the number of results to 1" do
@search.options = @search.options.merge("number" => 1)
@@ -127,8 +142,13 @@
with(:query => {:q => "twitter", :rpp => "200"}).
should have_been_made
a_request(:get, "https://search.twitter.com/search.json").
- with(:query => {:q => "twitter", :rpp => "145", :max_id => "194521261307727871"}).
- should have_been_made
+ with(:query => {:q => "twitter", :rpp => "200", :max_id => "194521261307727871"}).
+ should have_been_made.times(7)
+ (5..185).step(20).to_a.reverse.each do |count|
+ a_request(:get, "https://search.twitter.com/search.json").
+ with(:query => {:q => "twitter", :rpp => count, :max_id => "194521261307727871"}).
+ should have_been_made
+ end
end
end
end

0 comments on commit 929dd96

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