Skip to content

Commit

Permalink
Add retweets_of_me command
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Jan 20, 2014
1 parent 4af70ad commit da236d1
Show file tree
Hide file tree
Showing 2 changed files with 236 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/t/cli.rb
Expand Up @@ -610,6 +610,25 @@ def retweets(user = nil)
end
map %w[rts] => :retweets

desc 'retweets_of_me', "Returns the #{DEFAULT_NUM_RESULTS} most recent Tweets of the authenticated user that have been retweeted by others."
method_option 'csv', :aliases => '-c', :type => :boolean, :desc => 'Output in CSV format.'
method_option 'decode_uris', :aliases => '-d', :type => :boolean, :desc => 'Decodes t.co URLs into their original form.'
method_option 'id', :aliases => '-i', :type => :boolean, :desc => 'Specify user via ID instead of screen name.'
method_option 'long', :aliases => '-l', :type => :boolean, :desc => 'Output in long format.'
method_option 'number', :aliases => '-n', :type => :numeric, :default => DEFAULT_NUM_RESULTS, :desc => 'Limit the number of results.'
method_option 'relative_dates', :aliases => '-a', :type => :boolean, :desc => 'Show relative dates.'
method_option 'reverse', :aliases => '-r', :type => :boolean, :desc => 'Reverse the order of the sort.'
def retweets_of_me(user = nil)
count = options['number'] || DEFAULT_NUM_RESULTS
opts = {}
opts[:include_entities] = !!options['decode_uris']
tweets = collect_with_count(count) do |count_opts|
client.retweets_of_me(count_opts.merge(opts))
end
print_tweets(tweets)
end
map %w[retweetsofme] => :retweets_of_me

desc 'ruler', 'Prints a 140-character ruler'
method_option 'indent', :aliases => '-i', :type => :numeric, :default => 0, :desc => 'The number of space to print before the ruler.'
def ruler
Expand Down
217 changes: 217 additions & 0 deletions spec/cli_spec.rb
Expand Up @@ -2795,6 +2795,223 @@
end
end

describe '#retweets_of_me' do
before do
stub_get('/1.1/statuses/retweets_of_me.json').with(:query => {:count => '20', :include_entities => 'false'}).to_return(:body => fixture('statuses.json'))
end
context 'without arguments' do
it 'requests the correct resource' do
@cli.retweets_of_me
expect(a_get('/1.1/statuses/retweets_of_me.json').with(:query => {:count => '20', :include_entities => 'false'})).to have_been_made
end
it 'has the correct output' do
@cli.retweets_of_me
expect($stdout.string).to eq <<-eos
@mutgoff
Happy Birthday @imdane. Watch out for those @rally pranksters!
@ironicsans
If you like good real-life stories, check out @NarrativelyNY's just-launched
site http://t.co/wiUL07jE (and also visit http://t.co/ZoyQxqWA)
@pat_shaughnessy
Something else to vote for: "New Rails workshops to bring more women into the
Boston software scene" http://t.co/eNBuckHc /cc @bostonrb
@calebelston
Pushing the button to launch the site. http://t.co/qLoEn5jG
@calebelston
RT @olivercameron: Mosaic looks cool: http://t.co/A8013C9k
@fivethirtyeight
The Weatherman is Not a Moron: http://t.co/ZwL5Gnq5. An excerpt from my book,
THE SIGNAL AND THE NOISE (http://t.co/fNXj8vCE)
@codeforamerica
RT @randomhacks: Going to Code Across Austin II: Y'all Come Hack Now, Sat,
Sep 8 http://t.co/Sk5BM7U3 We'll see y'all there! #rhok @codeforamerica
@TheaClay
@fbjork
RT @jondot: Just published: "Pragmatic Concurrency With #Ruby"
http://t.co/kGEykswZ /cc @JRuby @headius
@mbostock
If you are wondering how we computed the split bubbles: http://t.co/BcaqSs5u
@FakeDorsey
"Write drunk. Edit sober."—Ernest Hemingway
@al3x
RT @wcmaier: Better banking through better ops: build something new with us
@Simplify (remote, PDX) http://t.co/8WgzKZH3
@calebelston
We just announced Mosaic, what we've been working on since the Yobongo
acquisition. My personal post, http://t.co/ELOyIRZU @heymosaic
@BarackObama
Donate $10 or more --> get your favorite car magnet: http://t.co/NfRhl2s2
#Obama2012
@JEG2
RT @tenderlove: If corporations are people, can we use them to drive in the
carpool lane?
@eveningedition
LDN—Obama's nomination; Putin woos APEC; Bombs hit Damascus; Quakes shake
China; Canada cuts Iran ties; weekend read: http://t.co/OFs6dVW4
@dhh
RT @ggreenwald: Democrats parade Osama bin Laden's corpse as their proudest
achievement: why this goulish jingoism is so warped http://t.co/kood278s
@jasonfried
The story of Mars Curiosity's gears, made by a factory in Rockford, IL:
http://t.co/MwCRsHQg
@sferik
@episod @twitterapi now https://t.co/I17jUTu2 and https://t.co/deDu4Hgw seem
to be missing "1.1" from the URL.
@sferik
@episod @twitterapi Did you catch https://t.co/VHsQvZT0 as well?
@dwiskus
Gentlemen, you can't fight in here! This is the war room!
http://t.co/kMxMYyqF
eos
end
end
context '--csv' do
before do
@cli.options = @cli.options.merge('csv' => true)
end
it 'outputs in CSV format' do
@cli.retweets_of_me
expect($stdout.string).to eq <<-eos
ID,Posted at,Screen name,Text
4611686018427387904,2012-09-07 16:35:24 +0000,mutgoff,Happy Birthday @imdane. Watch out for those @rally pranksters!
244111183165157376,2012-09-07 16:33:36 +0000,ironicsans,"If you like good real-life stories, check out @NarrativelyNY's just-launched site http://t.co/wiUL07jE (and also visit http://t.co/ZoyQxqWA)"
244110336414859264,2012-09-07 16:30:14 +0000,pat_shaughnessy,"Something else to vote for: ""New Rails workshops to bring more women into the Boston software scene"" http://t.co/eNBuckHc /cc @bostonrb"
244109797308379136,2012-09-07 16:28:05 +0000,calebelston,Pushing the button to launch the site. http://t.co/qLoEn5jG
244108728834592770,2012-09-07 16:23:50 +0000,calebelston,RT @olivercameron: Mosaic looks cool: http://t.co/A8013C9k
244107890632294400,2012-09-07 16:20:31 +0000,fivethirtyeight,"The Weatherman is Not a Moron: http://t.co/ZwL5Gnq5. An excerpt from my book, THE SIGNAL AND THE NOISE (http://t.co/fNXj8vCE)"
244107823733174272,2012-09-07 16:20:15 +0000,codeforamerica,"RT @randomhacks: Going to Code Across Austin II: Y'all Come Hack Now, Sat, Sep 8 http://t.co/Sk5BM7U3 We'll see y'all there! #rhok @codeforamerica @TheaClay"
244107236262170624,2012-09-07 16:17:55 +0000,fbjork,"RT @jondot: Just published: ""Pragmatic Concurrency With #Ruby"" http://t.co/kGEykswZ /cc @JRuby @headius"
244106476048764928,2012-09-07 16:14:53 +0000,mbostock,If you are wondering how we computed the split bubbles: http://t.co/BcaqSs5u
244105599351148544,2012-09-07 16:11:24 +0000,FakeDorsey,"""Write drunk. Edit sober.""—Ernest Hemingway"
244104558433951744,2012-09-07 16:07:16 +0000,al3x,"RT @wcmaier: Better banking through better ops: build something new with us @Simplify (remote, PDX) http://t.co/8WgzKZH3"
244104146997870594,2012-09-07 16:05:38 +0000,calebelston,"We just announced Mosaic, what we've been working on since the Yobongo acquisition. My personal post, http://t.co/ELOyIRZU @heymosaic"
244103057175113729,2012-09-07 16:01:18 +0000,BarackObama,Donate $10 or more --> get your favorite car magnet: http://t.co/NfRhl2s2 #Obama2012
244102834398851073,2012-09-07 16:00:25 +0000,JEG2,"RT @tenderlove: If corporations are people, can we use them to drive in the carpool lane?"
244102741125890048,2012-09-07 16:00:03 +0000,eveningedition,LDN—Obama's nomination; Putin woos APEC; Bombs hit Damascus; Quakes shake China; Canada cuts Iran ties; weekend read: http://t.co/OFs6dVW4
244102729860009984,2012-09-07 16:00:00 +0000,dhh,RT @ggreenwald: Democrats parade Osama bin Laden's corpse as their proudest achievement: why this goulish jingoism is so warped http://t.co/kood278s
244102490646278146,2012-09-07 15:59:03 +0000,jasonfried,"The story of Mars Curiosity's gears, made by a factory in Rockford, IL: http://t.co/MwCRsHQg"
244102209942458368,2012-09-07 15:57:56 +0000,sferik,"@episod @twitterapi now https://t.co/I17jUTu2 and https://t.co/deDu4Hgw seem to be missing ""1.1"" from the URL."
244100411563339777,2012-09-07 15:50:47 +0000,sferik,@episod @twitterapi Did you catch https://t.co/VHsQvZT0 as well?
244099460672679938,2012-09-07 15:47:01 +0000,dwiskus,"Gentlemen, you can't fight in here! This is the war room! http://t.co/kMxMYyqF"
eos
end
end
context '--decode-uris' do
before do
@cli.options = @cli.options.merge('decode_uris' => true)
stub_get('/1.1/statuses/retweets_of_me.json').with(:query => {:count => '20', :include_entities => 'true'}).to_return(:body => fixture('statuses.json'))
end
it 'requests the correct resource' do
@cli.retweets_of_me
expect(a_get('/1.1/statuses/retweets_of_me.json').with(:query => {:count => '20', :include_entities => 'true'})).to have_been_made
end
end
context '--long' do
before do
@cli.options = @cli.options.merge('long' => true)
end
it 'outputs in long format' do
@cli.retweets_of_me
expect($stdout.string).to eq <<-eos
ID Posted at Screen name Text
4611686018427387904 Sep 7 08:35 @mutgoff Happy Birthday @imdane. ...
244111183165157376 Sep 7 08:33 @ironicsans If you like good real-li...
244110336414859264 Sep 7 08:30 @pat_shaughnessy Something else to vote f...
244109797308379136 Sep 7 08:28 @calebelston Pushing the button to la...
244108728834592770 Sep 7 08:23 @calebelston RT @olivercameron: Mosai...
244107890632294400 Sep 7 08:20 @fivethirtyeight The Weatherman is Not a ...
244107823733174272 Sep 7 08:20 @codeforamerica RT @randomhacks: Going t...
244107236262170624 Sep 7 08:17 @fbjork RT @jondot: Just publish...
244106476048764928 Sep 7 08:14 @mbostock If you are wondering how...
244105599351148544 Sep 7 08:11 @FakeDorsey "Write drunk. Edit sober...
244104558433951744 Sep 7 08:07 @al3x RT @wcmaier: Better bank...
244104146997870594 Sep 7 08:05 @calebelston We just announced Mosaic...
244103057175113729 Sep 7 08:01 @BarackObama Donate $10 or more --> g...
244102834398851073 Sep 7 08:00 @JEG2 RT @tenderlove: If corpo...
244102741125890048 Sep 7 08:00 @eveningedition LDN—Obama's nomination; ...
244102729860009984 Sep 7 08:00 @dhh RT @ggreenwald: Democrat...
244102490646278146 Sep 7 07:59 @jasonfried The story of Mars Curios...
244102209942458368 Sep 7 07:57 @sferik @episod @twitterapi now ...
244100411563339777 Sep 7 07:50 @sferik @episod @twitterapi Did ...
244099460672679938 Sep 7 07:47 @dwiskus Gentlemen, you can't fig...
eos
end
context '--reverse' do
before do
@cli.options = @cli.options.merge('reverse' => true)
end
it 'reverses the order of the sort' do
@cli.retweets_of_me
expect($stdout.string).to eq <<-eos
ID Posted at Screen name Text
244099460672679938 Sep 7 07:47 @dwiskus Gentlemen, you can't fig...
244100411563339777 Sep 7 07:50 @sferik @episod @twitterapi Did ...
244102209942458368 Sep 7 07:57 @sferik @episod @twitterapi now ...
244102490646278146 Sep 7 07:59 @jasonfried The story of Mars Curios...
244102729860009984 Sep 7 08:00 @dhh RT @ggreenwald: Democrat...
244102741125890048 Sep 7 08:00 @eveningedition LDN—Obama's nomination; ...
244102834398851073 Sep 7 08:00 @JEG2 RT @tenderlove: If corpo...
244103057175113729 Sep 7 08:01 @BarackObama Donate $10 or more --> g...
244104146997870594 Sep 7 08:05 @calebelston We just announced Mosaic...
244104558433951744 Sep 7 08:07 @al3x RT @wcmaier: Better bank...
244105599351148544 Sep 7 08:11 @FakeDorsey "Write drunk. Edit sober...
244106476048764928 Sep 7 08:14 @mbostock If you are wondering how...
244107236262170624 Sep 7 08:17 @fbjork RT @jondot: Just publish...
244107823733174272 Sep 7 08:20 @codeforamerica RT @randomhacks: Going t...
244107890632294400 Sep 7 08:20 @fivethirtyeight The Weatherman is Not a ...
244108728834592770 Sep 7 08:23 @calebelston RT @olivercameron: Mosai...
244109797308379136 Sep 7 08:28 @calebelston Pushing the button to la...
244110336414859264 Sep 7 08:30 @pat_shaughnessy Something else to vote f...
244111183165157376 Sep 7 08:33 @ironicsans If you like good real-li...
4611686018427387904 Sep 7 08:35 @mutgoff Happy Birthday @imdane. ...
eos
end
end
end
context '--number' do
before do
stub_get('/1.1/statuses/retweets_of_me.json').with(:query => {:count => '1', :include_entities => 'false'}).to_return(:body => fixture('statuses.json'))
stub_get('/1.1/statuses/retweets_of_me.json').with(:query => {:count => '200', :include_entities => 'false'}).to_return(:body => fixture('statuses.json'))
(1..181).step(20) do |count|
stub_get('/1.1/statuses/retweets_of_me.json').with(:query => {:count => count, :max_id => '244099460672679937', :include_entities => 'false'}).to_return(:body => fixture('statuses.json'))
end
end
it 'limits the number of results to 1' do
@cli.options = @cli.options.merge('number' => 1)
@cli.retweets_of_me
expect(a_get('/1.1/statuses/retweets_of_me.json').with(:query => {:count => '1', :include_entities => 'false'})).to have_been_made
end
it 'limits the number of results to 201' do
@cli.options = @cli.options.merge('number' => 201)
@cli.retweets_of_me
expect(a_get('/1.1/statuses/retweets_of_me.json').with(:query => {:count => '200', :include_entities => 'false'})).to have_been_made
(1..181).step(20) do |count|
expect(a_get('/1.1/statuses/retweets_of_me.json').with(:query => {:count => count, :max_id => '244099460672679937', :include_entities => 'false'})).to have_been_made
end
end
end
end

describe '#ruler' do
it 'has the correct output' do
@cli.ruler
Expand Down

0 comments on commit da236d1

Please sign in to comment.