Skip to content

Commit

Permalink
Merge 6187f38 into 00389d0
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Abraham committed Jan 4, 2018
2 parents 00389d0 + 6187f38 commit 8a2b2ac
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -14,6 +14,7 @@ group :test do
gem 'timecop'
gem 'tins'
gem 'webmock', '>= 1.10.1'
gem 'byebug'
end

gemspec
35 changes: 35 additions & 0 deletions lib/t/cli.rb
Expand Up @@ -14,6 +14,7 @@
require 't/set'
require 't/stream'
require 't/utils'
require 'byebug'

module T
class CLI < Thor
Expand Down Expand Up @@ -112,6 +113,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)
byebug
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 +953,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
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

0 comments on commit 8a2b2ac

Please sign in to comment.