Skip to content

Commit

Permalink
add t muted command
Browse files Browse the repository at this point in the history
  • Loading branch information
johndbritton committed Jul 22, 2014
1 parent 38306fd commit 9224de2
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/t/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,23 @@ def mute(user, *users)
say "Run `#{File.basename($PROGRAM_NAME)} delete mute #{muted_users.collect { |muted_user| "@#{muted_user.screen_name}" }.join(' ')}` to unmute."
end

desc 'muted [USER]', 'Returns a list of the people you have muted on Twitter.'
method_option 'csv', :aliases => '-c', :type => :boolean, :desc => 'Output in CSV format.'
method_option 'long', :aliases => '-l', :type => :boolean, :desc => 'Output in long format.'
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.'
method_option 'sort', :aliases => '-s', :type => :string, :enum => %w[favorites followers friends listed screen_name since tweets tweeted], :default => 'screen_name', :desc => 'Specify the order of the results.', :banner => 'ORDER'
method_option 'unsorted', :aliases => '-u', :type => :boolean, :desc => 'Output is not sorted.'
def muted
muted_ids = client.muted_ids.to_a
require 'retryable'
muted_users = retryable(:tries => 3, :on => Twitter::Error, :sleep => 0) do
client.users(muted_ids)
end
print_users(muted_users)
end
map %w[mutes] => :muted

desc 'open USER', "Opens that user's profile in a web browser."
method_option 'display-uri', :aliases => '-d', :type => :boolean, :desc => 'Display the requested URL instead of attempting to open it.'
method_option 'id', :aliases => '-i', :type => :boolean, :desc => 'Specify user via ID instead of screen name.'
Expand Down
16 changes: 16 additions & 0 deletions spec/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2422,6 +2422,22 @@
end
end

describe '#muted' do
before do
stub_get('/1.1/mutes/users/ids.json').with(:query => {:cursor => '-1'}).to_return(:body => fixture('muted_ids.json'), :headers => {:content_type => 'application/json; charset=utf-8'})
stub_post('/1.1/users/lookup.json').with(:body => {:user_id => '14098423'}).to_return(:body => fixture('muted_users.json'), :headers => {:content_type => 'application/json; charset=utf-8'})
end
it 'requests the correct resource' do
@cli.muted
expect(a_get('/1.1/mutes/users/ids.json').with(:query => {:cursor => '-1'})).to have_been_made
expect(a_post('/1.1/users/lookup.json').with(:body => {:user_id => '14098423'})).to have_been_made
end
it 'has the correct output' do
@cli.muted
expect($stdout.string.chomp).to eq 'johndbritton'
end
end

describe '#open' do
before do
@cli.options = @cli.options.merge('display-uri' => true)
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/muted_ids.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"previous_cursor_str":"0","next_cursor":0,"ids":[14098423],"previous_cursor":0,"next_cursor_str":"0"}
1 change: 1 addition & 0 deletions spec/fixtures/muted_users.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"id":14098423,"id_str":"14098423","name":"John Britton","screen_name":"johndbritton","location":"New York, NY","description":"Hacker At-Large. Curious. College escapee. World traveling vagabond. Education Liaison @github. Volunteer @p2pu. Mozillian. @twilio alum.","url":"http://t.co/0gTrXsBkwy","entities":{"url":{"urls":[{"url":"http://t.co/0gTrXsBkwy","expanded_url":"http://johndbritton.com","display_url":"johndbritton.com","indices":[0,22]}]},"description":{"urls":[]}},"protected":false,"followers_count":3691,"friends_count":1550,"listed_count":255,"created_at":"Sat Mar 08 01:54:24 +0000 2008","favourites_count":93,"utc_offset":-14400,"time_zone":"Eastern Time (US & Canada)","geo_enabled":true,"verified":false,"statuses_count":6389,"lang":"en","status":{"created_at":"Tue Jul 22 08:48:21 +0000 2014","id":491505014268256260,"id_str":"491505014268256256","text":"I'm hacking when I should be sleeping.","source":"<a href=\"http://itunes.apple.com/us/app/twitter/id409789998?mt=12\" rel=\"nofollow\">Twitter for Mac</a>","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"geo":null,"coordinates":null,"place":null,"contributors":null,"retweet_count":0,"favorite_count":0,"entities":{"hashtags":[],"symbols":[],"urls":[],"user_mentions":[]},"favorited":false,"retweeted":false,"lang":"en"},"contributors_enabled":false,"is_translator":false,"is_translation_enabled":false,"profile_background_color":"333333","profile_background_image_url":"http://pbs.twimg.com/profile_background_images/4192334/www.johndbritton.com.png","profile_background_image_url_https":"https://pbs.twimg.com/profile_background_images/4192334/www.johndbritton.com.png","profile_background_tile":false,"profile_image_url":"http://pbs.twimg.com/profile_images/490680869263122432/X8X4c1MI_normal.jpeg","profile_image_url_https":"https://pbs.twimg.com/profile_images/490680869263122432/X8X4c1MI_normal.jpeg","profile_link_color":"0062A0","profile_sidebar_border_color":"333333","profile_sidebar_fill_color":"DDD7CD","profile_text_color":"666666","profile_use_background_image":true,"default_profile":false,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false}]

0 comments on commit 9224de2

Please sign in to comment.