Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions lib/t/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ def authorize
desc 'block USER [USER...]', 'Block users.'
method_option 'id', aliases: '-i', type: :boolean, desc: 'Specify input as Twitter user IDs instead of screen names.'
def block(user, *users)
return if invalid_users_present(user, users)

blocked_users, number = fetch_users(users.unshift(user), options) do |users_to_block|
client.block(users_to_block)
end
Expand Down Expand Up @@ -950,6 +952,38 @@ def whoami

private

def invalid_users_present(user, users)
not_found_flag = false
begin
if user_already_blocked?(user)
say "#{user} is already blocked\n"
end
rescue
say "#{user} not found \n"
return true if users.empty?
ensure
users.each do |user|
begin
return true if user_already_blocked?(user)
rescue
say "#{user} not found \n"
not_found_flag = true
next
end
end
not_found_flag
end
not_found_flag
end

def user_already_blocked?(user)
if client.block?(user)
say "#{user} is already blocked"
return true
end
return false
end

def extract_mentioned_screen_names(text)
valid_mention_preceding_chars = /(?:[^a-zA-Z0-9_!#\$%&*@@]|^|RT:?)/o
at_signs = /[@@]/
Expand Down
6 changes: 6 additions & 0 deletions spec/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@
@cli.block('sferik')
expect(a_post('/1.1/blocks/create.json').with(body: {screen_name: 'sferik'})).to have_been_made
end

it 'notifies of invalid user' do
@cli.block('vinuthalan')
expect($stdout.string).to match('@testcli blocked 1 user')
end

it 'has the correct output' do
@cli.block('sferik')
expect($stdout.string).to match(/^@testcli blocked 1 user/)
Expand Down