Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add RuboCop

  • Loading branch information...
commit a1e2424ed9293b8dc64f3a40a49177f3627025df 1 parent 15c14d6
@sferik authored
View
69 .rubocop.yml
@@ -0,0 +1,69 @@
+AllCops:
+ Includes:
+ - 'Gemfile'
+
+# Avoid long parameter lists
+ParameterLists:
+ Max: 3
+ CountKeywordArgs: true
+
+# Avoid more than `Max` levels of nesting.
+BlockNesting:
+ Max: 3
+
+# Align with the style guide.
+CollectionMethods:
+ PreferredMethods:
+ collect: 'map'
+ inject: 'reduce'
+ find: 'detect'
+ find_all: 'select'
+
+# Do not force public/protected/private keyword to be indented at the same
+# level as the def keyword. My personal preference is to outdent these keywords
+# because I think when scanning code it makes it easier to identify the
+# sections of code and visually separate them. When the keyword is at the same
+# level I think it sort of blends in with the def keywords and makes it harder
+# to scan the code and see where the sections are.
+AccessModifierIndentation:
+ Enabled: false
+
+# Limit line length
+LineLength:
+ Enabled: false
+
+# Disable documentation checking until a class needs to be documented once
+Documentation:
+ Enabled: false
+
+# Enforce Ruby 1.8-compatible hash syntax
+HashSyntax:
+ EnforcedStyle: hash_rockets
+
+# No spaces inside hash literals
+SpaceInsideHashLiteralBraces:
+ EnforcedStyle: no_space
+
+# Allow dots at the end of lines
+DotPosition:
+ Enabled: false
+
+# Don't require magic comment at the top of every file
+Encoding:
+ Enabled: false
+
+# Don't prefer sprintf to String#%
+FavorSprintf:
+ Enabled: false
+
+# Trailing whitespace is required to test output
+TrailingWhitespace:
+ Enabled: false
+
+# Thor makes it hard to write short classes
+ClassLength:
+ Enabled: false
+
+# Thor makes it hard to write short methods
+MethodLength:
+ Enabled: false
View
2  CONTRIBUTING.md
@@ -37,7 +37,7 @@ Ideally, a bug report should include a pull request with failing specs.
3. Add specs for your unimplemented feature or bug fix.
4. Run `bundle exec rake spec`. If your specs pass, return to step 3.
5. Implement your feature or bug fix.
-6. Run `bundle exec rake spec`. If your specs fail, return to step 5.
+6. Run `bundle exec rake default`. If your specs fail, return to step 5.
7. Run `open coverage/index.html`. If your changes are not completely covered
by your tests, return to step 3.
8. Add, commit, and push your changes.
View
7 Gemfile
@@ -6,12 +6,17 @@ gem 'jruby-openssl', :platforms => :jruby
group :development do
gem 'guard-rspec'
gem 'pry'
- gem 'pry-debugger', :platforms => :mri_19
+ gem 'pry-rescue'
+ platforms :ruby_19, :ruby_20 do
+ gem 'pry-debugger'
+ gem 'pry-stack_explorer'
+ end
end
group :test do
gem 'coveralls', :require => false
gem 'rspec', '>= 2.14'
+ gem 'rubocop', '>= 0.15', :platforms => [:ruby_19, :ruby_20]
gem 'simplecov', :require => false
gem 'timecop'
gem 'webmock', '>= 1.10.1'
View
12 Rakefile
@@ -4,8 +4,18 @@ Bundler::GemHelper.install_tasks
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
+begin
+ require 'rubocop/rake_task'
+ Rubocop::RakeTask.new
+rescue LoadError
+ desc 'Run RuboCop'
+ task :rubocop do
+ $stderr.puts 'Rubocop is disabled'
+ end
+end
+
Dir.glob('tasks/*.rake').each { |r| import r }
task :release => 'completion:zsh'
task :test => :spec
-task :default => :spec
+task :default => [:spec, :rubocop]
View
22 bin/t
@@ -2,7 +2,7 @@
# Trap interrupts to quit cleanly. See
# https://twitter.com/mitchellh/status/283014103189053442
-Signal.trap("INT") { exit 1 }
+Signal.trap('INT') { exit 1 }
require 'oauth'
require 't'
@@ -11,7 +11,7 @@ require 'twitter'
# Output message to $stderr, prefixed with the program name
def pute(*args)
first = args.shift.dup
- first.insert(0, "#{$0}: ")
+ first.insert(0, "#{$PROGRAM_NAME}: ")
args.unshift(first)
$stderr.puts(*args)
end
@@ -19,29 +19,29 @@ end
begin
T::CLI.start(ARGV)
rescue Interrupt
- pute "Quitting..."
+ pute 'Quitting...'
exit 1
rescue OAuth::Unauthorized
- pute "Authorization failed"
+ pute 'Authorization failed'
exit 1
rescue Twitter::Error::TooManyRequests => error
pute error.message,
- "The rate limit for this request will reset in #{error.rate_limit.reset_in} seconds.",
- "While you wait, consider making a polite request for Twitter to increase the API rate limit at https://dev.twitter.com/discussions/10644"
+ "The rate limit for this request will reset in #{error.rate_limit.reset_in} seconds.",
+ 'While you wait, consider making a polite request for Twitter to increase the API rate limit at https://dev.twitter.com/discussions/10644'
exit 1
rescue Twitter::Error::BadRequest => error
pute error.message,
- "Run `t authorize` to authorize."
+ 'Run `t authorize` to authorize.'
exit 1
rescue Twitter::Error::Forbidden, Twitter::Error::Unauthorized => error
pute error.message
- if error.message == "Error processing your OAuth request: Read-only application cannot POST" ||
- error.message == "This application is not allowed to access or delete your direct messages"
+ if error.message == 'Error processing your OAuth request: Read-only application cannot POST' ||
+ error.message == 'This application is not allowed to access or delete your direct messages'
$stderr.puts(%q(Make sure to set your Twitter application's Access Level to "Read, Write and Access direct messages".))
require 'thor'
- Thor::Shell::Basic.new.ask "Press [Enter] to open the Twitter Developer site."
+ Thor::Shell::Basic.new.ask 'Press [Enter] to open the Twitter Developer site.'
require 'launchy'
- Launchy.open("https://dev.twitter.com/apps") { |u,o,e| $stderr.puts "Manually open #{u}" }
+ Launchy.open('https://dev.twitter.com/apps') { |u, o, e| $stderr.puts "Manually open #{u}" }
end
exit 1
rescue Twitter::Error => error
View
16 lib/t.rb
@@ -3,7 +3,6 @@
module T
class << self
-
# Convert time to local time by applying the `utc_offset` setting.
def local_time(time)
utc_offset ? (time.dup.utc + utc_offset) : time.localtime
@@ -15,14 +14,13 @@ def local_time(time)
def utc_offset=(offset)
@utc_offset = case offset
- when String
- Time.zone_offset(offset)
- when NilClass
- nil
- else
- offset.to_i
- end
+ when String
+ Time.zone_offset(offset)
+ when NilClass
+ nil
+ else
+ offset.to_i
+ end
end
-
end
end
View
665 lib/t/cli.rb
@@ -24,20 +24,20 @@ class CLI < Thor
include T::Utils
DEFAULT_NUM_RESULTS = 20
- DIRECT_MESSAGE_HEADINGS = ["ID", "Posted at", "Screen name", "Text"]
- TREND_HEADINGS = ["WOEID", "Parent ID", "Type", "Name", "Country"]
+ DIRECT_MESSAGE_HEADINGS = ['ID', 'Posted at', 'Screen name', 'Text']
+ TREND_HEADINGS = ['WOEID', 'Parent ID', 'Type', 'Name', 'Country']
check_unknown_options!
- class_option "color", :aliases => "-C", :type => :string, :enum => %w(auto never), :default => "auto", :desc => "Control how color is used in output"
- class_option "profile", :aliases => "-P", :type => :string, :default => File.join(File.expand_path("~"), T::RCFile::FILE_NAME), :desc => "Path to RC file", :banner => "FILE"
+ class_option 'color', :aliases => '-C', :type => :string, :enum => %w(auto never), :default => 'auto', :desc => 'Control how color is used in output'
+ class_option 'profile', :aliases => '-P', :type => :string, :default => File.join(File.expand_path('~'), T::RCFile::FILE_NAME), :desc => 'Path to RC file', :banner => 'FILE'
def initialize(*)
@rcfile = T::RCFile.instance
super
end
- desc "accounts", "List accounts"
+ desc 'accounts', 'List accounts'
def accounts
@rcfile.path = options['profile'] if options['profile']
@rcfile.profiles.each do |profile|
@@ -48,53 +48,53 @@ def accounts
end
end
- desc "authorize", "Allows an application to request user authorization"
- method_option "display-uri", :aliases => "-d", :type => :boolean, :default => false, :desc => "Display the authorization URL instead of attempting to open it."
+ desc 'authorize', 'Allows an application to request user authorization'
+ method_option 'display-uri', :aliases => '-d', :type => :boolean, :default => false, :desc => 'Display the authorization URL instead of attempting to open it.'
def authorize
@rcfile.path = options['profile'] if options['profile']
if @rcfile.empty?
say "Welcome! Before you can use t, you'll first need to register an"
- say "application with Twitter. Just follow the steps below:"
- say " 1. Sign in to the Twitter Developer site and click"
+ say 'application with Twitter. Just follow the steps below:'
+ say ' 1. Sign in to the Twitter Developer site and click'
say " \"Create a new application\"."
- say " 2. Complete the required fields and submit the form."
- say " Note: Your application must have a unique name."
+ say ' 2. Complete the required fields and submit the form.'
+ say ' Note: Your application must have a unique name.'
say " We recommend: \"<your handle>/t\"."
- say " 3. Go to the Settings tab of your application, and change the"
+ say ' 3. Go to the Settings tab of your application, and change the'
say " Access setting to \"Read, Write and Access direct messages\"."
- say " 4. Go to the Details tab to view the consumer key and secret,"
+ say ' 4. Go to the Details tab to view the consumer key and secret,'
say " which you'll need to copy and paste below when prompted."
say
- ask "Press [Enter] to open the Twitter Developer site."
+ ask 'Press [Enter] to open the Twitter Developer site.'
say
else
say "It looks like you've already registered an application with Twitter."
- say "To authorize a new account, just follow the steps below:"
- say " 1. Sign in to the Twitter Developer site."
+ say 'To authorize a new account, just follow the steps below:'
+ say ' 1. Sign in to the Twitter Developer site.'
say " 2. Select the application for which you'd like to authorize an account."
- say " 3. Copy and paste the consumer key and secret below when prompted."
+ say ' 3. Copy and paste the consumer key and secret below when prompted.'
say
- ask "Press [Enter] to open the Twitter Developer site."
+ ask 'Press [Enter] to open the Twitter Developer site.'
say
end
require 'launchy'
- open_or_print( "https://dev.twitter.com/apps", :dry_run => options['display-uri'] )
- key = ask "Enter your consumer key:"
- secret = ask "Enter your consumer secret:"
+ open_or_print('https://dev.twitter.com/apps', :dry_run => options['display-uri'])
+ key = ask 'Enter your consumer key:'
+ secret = ask 'Enter your consumer secret:'
consumer = OAuth::Consumer.new(key, secret, :site => Twitter::REST::Client::ENDPOINT)
request_token = consumer.get_request_token
uri = generate_authorize_uri(consumer, request_token)
say
- say "In a moment, you will be directed to the Twitter app authorization page."
- say "Perform the following steps to complete the authorization process:"
- say " 1. Sign in to Twitter."
+ say 'In a moment, you will be directed to the Twitter app authorization page.'
+ say 'Perform the following steps to complete the authorization process:'
+ say ' 1. Sign in to Twitter.'
say " 2. Press \"Authorize app\"."
- say " 3. Copy and paste the supplied PIN below when prompted."
+ say ' 3. Copy and paste the supplied PIN below when prompted.'
say
- ask "Press [Enter] to open the Twitter app authorization page."
+ ask 'Press [Enter] to open the Twitter app authorization page.'
say
open_or_print(uri, :dry_run => options['display-uri'])
- pin = ask "Enter the supplied PIN:"
+ pin = ask 'Enter the supplied PIN:'
access_token = request_token.get_access_token(:oauth_verifier => pin.chomp)
oauth_response = access_token.get('/1.1/account/verify_credentials.json?include_entities=false&skip_status=true')
screen_name = oauth_response.body.match(/"screen_name"\s*:\s*"(.*?)"/).captures.first
@@ -108,26 +108,26 @@ def authorize
}
}
@rcfile.active_profile = {'username' => screen_name, 'consumer_key' => key}
- say "Authorization successful."
+ say 'Authorization successful.'
end
- desc "block USER [USER...]", "Block users."
- method_option "id", :aliases => "-i", :type => :boolean, :default => false, :desc => "Specify input as Twitter user IDs instead of screen names."
+ desc 'block USER [USER...]', 'Block users.'
+ method_option 'id', :aliases => '-i', :type => :boolean, :default => false, :desc => 'Specify input as Twitter user IDs instead of screen names.'
def block(user, *users)
- users, number = fetch_users(users.unshift(user), options) do |users|
- client.block(users)
+ blocked_users, number = fetch_users(users.unshift(user), options) do |users_to_block|
+ client.block(users_to_block)
end
say "@#{@rcfile.active_profile[0]} blocked #{pluralize(number, 'user')}."
say
- say "Run `#{File.basename($0)} delete block #{users.map{|user| "@#{user.screen_name}"}.join(' ')}` to unblock."
+ say "Run `#{File.basename($PROGRAM_NAME)} delete block #{blocked_users.map { |blocked_user| "@#{blocked_user.screen_name}"}.join(' ')}` to unblock."
end
- desc "direct_messages", "Returns the #{DEFAULT_NUM_RESULTS} most recent Direct Messages sent to you."
- method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format."
- method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format."
- method_option "number", :aliases => "-n", :type => :numeric, :default => DEFAULT_NUM_RESULTS, :desc => "Limit the number of results."
- method_option "reverse", :aliases => "-r", :type => :boolean, :default => false, :desc => "Reverse the order of the sort."
- def direct_messages
+ desc 'direct_messages', "Returns the #{DEFAULT_NUM_RESULTS} most recent Direct Messages sent to you."
+ method_option 'csv', :aliases => '-c', :type => :boolean, :default => false, :desc => 'Output in CSV format.'
+ method_option 'long', :aliases => '-l', :type => :boolean, :default => false, :desc => 'Output in long format.'
+ method_option 'number', :aliases => '-n', :type => :numeric, :default => DEFAULT_NUM_RESULTS, :desc => 'Limit the number of results.'
+ method_option 'reverse', :aliases => '-r', :type => :boolean, :default => false, :desc => 'Reverse the order of the sort.'
+ def direct_messages # rubocop:disable CyclomaticComplexity
count = options['number'] || DEFAULT_NUM_RESULTS
direct_messages = collect_with_count(count) do |count_opts|
client.direct_messages(count_opts)
@@ -144,7 +144,7 @@ def direct_messages
array = direct_messages.map do |direct_message|
[direct_message.id, ls_formatted_time(direct_message), "@#{direct_message.sender.screen_name}", HTMLEntities.new.decode(direct_message.text).gsub(/\n+/, ' ')]
end
- format = options['format'] || DIRECT_MESSAGE_HEADINGS.size.times.map{"%s"}
+ format = options['format'] || DIRECT_MESSAGE_HEADINGS.size.times.map { '%s' }
print_table_with_headings(array, DIRECT_MESSAGE_HEADINGS, format)
else
direct_messages.each do |direct_message|
@@ -154,12 +154,12 @@ def direct_messages
end
map %w(directmessages dms) => :direct_messages
- desc "direct_messages_sent", "Returns the #{DEFAULT_NUM_RESULTS} most recent Direct Messages you've sent."
- method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format."
- method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format."
- method_option "number", :aliases => "-n", :type => :numeric, :default => DEFAULT_NUM_RESULTS, :desc => "Limit the number of results."
- method_option "reverse", :aliases => "-r", :type => :boolean, :default => false, :desc => "Reverse the order of the sort."
- def direct_messages_sent
+ desc 'direct_messages_sent', "Returns the #{DEFAULT_NUM_RESULTS} most recent Direct Messages you've sent."
+ method_option 'csv', :aliases => '-c', :type => :boolean, :default => false, :desc => 'Output in CSV format.'
+ method_option 'long', :aliases => '-l', :type => :boolean, :default => false, :desc => 'Output in long format.'
+ method_option 'number', :aliases => '-n', :type => :numeric, :default => DEFAULT_NUM_RESULTS, :desc => 'Limit the number of results.'
+ method_option 'reverse', :aliases => '-r', :type => :boolean, :default => false, :desc => 'Reverse the order of the sort.'
+ def direct_messages_sent # rubocop:disable CyclomaticComplexity
count = options['number'] || DEFAULT_NUM_RESULTS
direct_messages = collect_with_count(count) do |count_opts|
client.direct_messages_sent(count_opts)
@@ -176,7 +176,7 @@ def direct_messages_sent
array = direct_messages.map do |direct_message|
[direct_message.id, ls_formatted_time(direct_message), "@#{direct_message.recipient.screen_name}", HTMLEntities.new.decode(direct_message.text).gsub(/\n+/, ' ')]
end
- format = options['format'] || DIRECT_MESSAGE_HEADINGS.size.times.map{"%s"}
+ format = options['format'] || DIRECT_MESSAGE_HEADINGS.size.times.map { '%s' }
print_table_with_headings(array, DIRECT_MESSAGE_HEADINGS, format)
else
direct_messages.each do |direct_message|
@@ -186,24 +186,20 @@ def direct_messages_sent
end
map %w(directmessagessent sent_messages sentmessages sms) => :direct_messages_sent
- desc "groupies [USER]", "Returns the list of people who follow you but you don't follow back."
- method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format."
- method_option "id", :aliases => "-i", :type => :boolean, :default => false, :desc => "Specify user via ID instead of screen name."
- method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format."
- method_option "reverse", :aliases => "-r", :type => :boolean, :default => false, :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, :default => false, :desc => "Output is not sorted."
- def groupies(user=nil)
+ desc 'groupies [USER]', "Returns the list of people who follow you but you don't follow back."
+ method_option 'csv', :aliases => '-c', :type => :boolean, :default => false, :desc => 'Output in CSV format.'
+ method_option 'id', :aliases => '-i', :type => :boolean, :default => false, :desc => 'Specify user via ID instead of screen name.'
+ method_option 'long', :aliases => '-l', :type => :boolean, :default => false, :desc => 'Output in long format.'
+ method_option 'reverse', :aliases => '-r', :type => :boolean, :default => false, :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, :default => false, :desc => 'Output is not sorted.'
+ def groupies(user = nil)
user = if user
- require 't/core_ext/string'
- if options['id']
- user.to_i
- else
- user.strip_ats
- end
- else
- client.verify_credentials.screen_name
- end
+ require 't/core_ext/string'
+ options['id'] ? user.to_i : user.strip_ats
+ else
+ client.verify_credentials.screen_name
+ end
follower_ids = Thread.new do
client.follower_ids(user).to_a
end
@@ -219,33 +215,25 @@ def groupies(user=nil)
end
map %w(disciples) => :groupies
- desc "dm USER MESSAGE", "Sends that person a Direct Message."
- method_option "id", :aliases => "-i", :type => :boolean, :default => false, :desc => "Specify user via ID instead of screen name."
+ desc 'dm USER MESSAGE', 'Sends that person a Direct Message.'
+ method_option 'id', :aliases => '-i', :type => :boolean, :default => false, :desc => 'Specify user via ID instead of screen name.'
def dm(user, message)
require 't/core_ext/string'
- user = if options['id']
- user.to_i
- else
- user.strip_ats
- end
+ user = options['id'] ? user.to_i : user.strip_ats
direct_message = client.create_direct_message(user, message)
say "Direct Message sent from @#{@rcfile.active_profile[0]} to @#{direct_message.recipient.screen_name}."
end
map %w(d m) => :dm
- desc "does_contain [USER/]LIST USER", "Find out whether a list contains a user."
- method_option "id", :aliases => "-i", :type => :boolean, :default => false, :desc => "Specify user via ID instead of screen name."
- def does_contain(list, user=nil)
+ desc 'does_contain [USER/]LIST USER', 'Find out whether a list contains a user.'
+ method_option 'id', :aliases => '-i', :type => :boolean, :default => false, :desc => 'Specify user via ID instead of screen name.'
+ def does_contain(list, user = nil)
owner, list = extract_owner(list, options)
if user.nil?
user = @rcfile.active_profile[0]
else
require 't/core_ext/string'
- user = if options['id']
- user = client.user(user.to_i).screen_name
- else
- user.strip_ats
- end
+ user = options['id'] ? client.user(user.to_i).screen_name : user.strip_ats
end
if client.list_member?(owner, list, user)
say "Yes, #{list} contains @#{user}."
@@ -256,23 +244,15 @@ def does_contain(list, user=nil)
end
map %w(dc doescontain) => :does_contain
- desc "does_follow USER [USER]", "Find out whether one user follows another."
- method_option "id", :aliases => "-i", :type => :boolean, :default => false, :desc => "Specify user via ID instead of screen name."
- def does_follow(user1, user2=nil)
+ desc 'does_follow USER [USER]', 'Find out whether one user follows another.'
+ method_option 'id', :aliases => '-i', :type => :boolean, :default => false, :desc => 'Specify user via ID instead of screen name.'
+ def does_follow(user1, user2 = nil)
require 't/core_ext/string'
- user1 = if options['id']
- client.user(user1.to_i).screen_name
- else
- user1.strip_ats
- end
+ user1 = options['id'] ? client.user(user1.to_i).screen_name : user1.strip_ats
if user2.nil?
user2 = @rcfile.active_profile[0]
else
- user2 = if options['id']
- client.user(user2.to_i).screen_name
- else
- user2.strip_ats
- end
+ user2 = options['id'] ? client.user(user2.to_i).screen_name : user2.strip_ats
end
if client.friendship?(user1, user2)
say "Yes, @#{user1} follows @#{user2}."
@@ -283,7 +263,7 @@ def does_follow(user1, user2=nil)
end
map %w(df doesfollow) => :does_follow
- desc "favorite TWEET_ID [TWEET_ID...]", "Marks Tweets as favorites."
+ desc 'favorite TWEET_ID [TWEET_ID...]', 'Marks Tweets as favorites.'
def favorite(status_id, *status_ids)
status_ids.unshift(status_id)
status_ids.map!(&:to_i)
@@ -294,19 +274,19 @@ def favorite(status_id, *status_ids)
number = favorites.length
say "@#{@rcfile.active_profile[0]} favorited #{pluralize(number, 'tweet')}."
say
- say "Run `#{File.basename($0)} delete favorite #{status_ids.join(' ')}` to unfavorite."
+ say "Run `#{File.basename($PROGRAM_NAME)} delete favorite #{status_ids.join(' ')}` to unfavorite."
end
map %w(fave favourite) => :favorite
- desc "favorites [USER]", "Returns the #{DEFAULT_NUM_RESULTS} most recent Tweets you favorited."
- method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format."
- method_option "id", :aliases => "-i", :type => :boolean, :default => false, :desc => "Specify user via ID instead of screen name."
- method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format."
- method_option "max_id", :aliases => "-m", :type => :numeric, :desc => "Returns only the results with an ID less than the specified ID."
- method_option "number", :aliases => "-n", :type => :numeric, :default => DEFAULT_NUM_RESULTS, :desc => "Limit the number of results."
- method_option "reverse", :aliases => "-r", :type => :boolean, :default => false, :desc => "Reverse the order of the sort."
- method_option "since_id", :aliases => "-s", :type => :numeric, :desc => "Returns only the results with an ID greater than the specified ID."
- def favorites(user=nil)
+ desc 'favorites [USER]', "Returns the #{DEFAULT_NUM_RESULTS} most recent Tweets you favorited."
+ method_option 'csv', :aliases => '-c', :type => :boolean, :default => false, :desc => 'Output in CSV format.'
+ method_option 'id', :aliases => '-i', :type => :boolean, :default => false, :desc => 'Specify user via ID instead of screen name.'
+ method_option 'long', :aliases => '-l', :type => :boolean, :default => false, :desc => 'Output in long format.'
+ method_option 'max_id', :aliases => '-m', :type => :numeric, :desc => 'Returns only the results with an ID less than the specified ID.'
+ method_option 'number', :aliases => '-n', :type => :numeric, :default => DEFAULT_NUM_RESULTS, :desc => 'Limit the number of results.'
+ method_option 'reverse', :aliases => '-r', :type => :boolean, :default => false, :desc => 'Reverse the order of the sort.'
+ method_option 'since_id', :aliases => '-s', :type => :numeric, :desc => 'Returns only the results with an ID greater than the specified ID.'
+ def favorites(user = nil) # rubocop:disable CyclomaticComplexity
count = options['number'] || DEFAULT_NUM_RESULTS
opts = {}
opts[:exclude_replies] = true if options['exclude'] == 'replies'
@@ -315,11 +295,7 @@ def favorites(user=nil)
opts[:since_id] = options['since_id'] if options['since_id']
if user
require 't/core_ext/string'
- user = if options['id']
- user.to_i
- else
- user.strip_ats
- end
+ user = options['id'] ? user.to_i : user.strip_ats
end
tweets = collect_with_count(count) do |count_opts|
client.favorites(user, count_opts.merge(opts))
@@ -328,32 +304,28 @@ def favorites(user=nil)
end
map %w(faves favourites) => :favorites
- desc "follow USER [USER...]", "Allows you to start following users."
- method_option "id", :aliases => "-i", :type => :boolean, :default => false, :desc => "Specify input as Twitter user IDs instead of screen names."
+ desc 'follow USER [USER...]', 'Allows you to start following users.'
+ method_option 'id', :aliases => '-i', :type => :boolean, :default => false, :desc => 'Specify input as Twitter user IDs instead of screen names.'
def follow(user, *users)
- users, number = fetch_users(users.unshift(user), options) do |users|
- client.follow(users)
+ followed_users, number = fetch_users(users.unshift(user), options) do |users_to_follow|
+ client.follow(users_to_follow)
end
say "@#{@rcfile.active_profile[0]} is now following #{pluralize(number, 'more user')}."
say
- say "Run `#{File.basename($0)} unfollow #{users.map{|user| "@#{user.screen_name}"}.join(' ')}` to stop."
+ say "Run `#{File.basename($PROGRAM_NAME)} unfollow #{followed_users.map { |followed_user| "@#{followed_user.screen_name}"}.join(' ')}` to stop."
end
- desc "followings [USER]", "Returns a list of the people you follow on Twitter."
- method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format."
- method_option "id", :aliases => "-i", :type => :boolean, :default => false, :desc => "Specify user via ID instead of screen name."
- method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format."
- method_option "reverse", :aliases => "-r", :type => :boolean, :default => false, :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, :default => false, :desc => "Output is not sorted."
- def followings(user=nil)
+ desc 'followings [USER]', 'Returns a list of the people you follow on Twitter.'
+ method_option 'csv', :aliases => '-c', :type => :boolean, :default => false, :desc => 'Output in CSV format.'
+ method_option 'id', :aliases => '-i', :type => :boolean, :default => false, :desc => 'Specify user via ID instead of screen name.'
+ method_option 'long', :aliases => '-l', :type => :boolean, :default => false, :desc => 'Output in long format.'
+ method_option 'reverse', :aliases => '-r', :type => :boolean, :default => false, :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, :default => false, :desc => 'Output is not sorted.'
+ def followings(user = nil)
if user
require 't/core_ext/string'
- user = if options['id']
- user.to_i
- else
- user.strip_ats
- end
+ user = options['id'] ? user.to_i : user.strip_ats
end
following_ids = client.friend_ids(user).to_a
require 'retryable'
@@ -363,21 +335,17 @@ def followings(user=nil)
print_users(users)
end
- desc "followers [USER]", "Returns a list of the people who follow you on Twitter."
- method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format."
- method_option "id", :aliases => "-i", :type => :boolean, :default => false, :desc => "Specify user via ID instead of screen name."
- method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format."
- method_option "reverse", :aliases => "-r", :type => :boolean, :default => false, :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, :default => false, :desc => "Output is not sorted."
- def followers(user=nil)
+ desc 'followers [USER]', 'Returns a list of the people who follow you on Twitter.'
+ method_option 'csv', :aliases => '-c', :type => :boolean, :default => false, :desc => 'Output in CSV format.'
+ method_option 'id', :aliases => '-i', :type => :boolean, :default => false, :desc => 'Specify user via ID instead of screen name.'
+ method_option 'long', :aliases => '-l', :type => :boolean, :default => false, :desc => 'Output in long format.'
+ method_option 'reverse', :aliases => '-r', :type => :boolean, :default => false, :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, :default => false, :desc => 'Output is not sorted.'
+ def followers(user = nil)
if user
require 't/core_ext/string'
- user = if options['id']
- user.to_i
- else
- user.strip_ats
- end
+ user = options['id'] ? user.to_i : user.strip_ats
end
follower_ids = client.follower_ids(user).to_a
require 'retryable'
@@ -387,24 +355,20 @@ def followers(user=nil)
print_users(users)
end
- desc "friends [USER]", "Returns the list of people who you follow and follow you back."
- method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format."
- method_option "id", :aliases => "-i", :type => :boolean, :default => false, :desc => "Specify user via ID instead of screen name."
- method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format."
- method_option "reverse", :aliases => "-r", :type => :boolean, :default => false, :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, :default => false, :desc => "Output is not sorted."
- def friends(user=nil)
+ desc 'friends [USER]', 'Returns the list of people who you follow and follow you back.'
+ method_option 'csv', :aliases => '-c', :type => :boolean, :default => false, :desc => 'Output in CSV format.'
+ method_option 'id', :aliases => '-i', :type => :boolean, :default => false, :desc => 'Specify user via ID instead of screen name.'
+ method_option 'long', :aliases => '-l', :type => :boolean, :default => false, :desc => 'Output in long format.'
+ method_option 'reverse', :aliases => '-r', :type => :boolean, :default => false, :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, :default => false, :desc => 'Output is not sorted.'
+ def friends(user = nil)
user = if user
- require 't/core_ext/string'
- if options['id']
- user.to_i
- else
- user.strip_ats
- end
- else
- client.verify_credentials.screen_name
- end
+ require 't/core_ext/string'
+ options['id'] ? user.to_i : user.strip_ats
+ else
+ client.verify_credentials.screen_name
+ end
following_ids = Thread.new do
client.friend_ids(user).to_a
end
@@ -419,24 +383,20 @@ def friends(user=nil)
print_users(users)
end
- desc "leaders [USER]", "Returns the list of people who you follow but don't follow you back."
- method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format."
- method_option "id", :aliases => "-i", :type => :boolean, :default => false, :desc => "Specify user via ID instead of screen name."
- method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format."
- method_option "reverse", :aliases => "-r", :type => :boolean, :default => false, :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, :default => false, :desc => "Output is not sorted."
- def leaders(user=nil)
+ desc 'leaders [USER]', "Returns the list of people who you follow but don't follow you back."
+ method_option 'csv', :aliases => '-c', :type => :boolean, :default => false, :desc => 'Output in CSV format.'
+ method_option 'id', :aliases => '-i', :type => :boolean, :default => false, :desc => 'Specify user via ID instead of screen name.'
+ method_option 'long', :aliases => '-l', :type => :boolean, :default => false, :desc => 'Output in long format.'
+ method_option 'reverse', :aliases => '-r', :type => :boolean, :default => false, :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, :default => false, :desc => 'Output is not sorted.'
+ def leaders(user = nil)
user = if user
- require 't/core_ext/string'
- if options['id']
- user.to_i
- else
- user.strip_ats
- end
- else
- client.verify_credentials.screen_name
- end
+ require 't/core_ext/string'
+ options['id'] ? user.to_i : user.strip_ats
+ else
+ client.verify_credentials.screen_name
+ end
following_ids = Thread.new do
client.friend_ids(user).to_a
end
@@ -451,36 +411,32 @@ def leaders(user=nil)
print_users(users)
end
- desc "lists [USER]", "Returns the lists created by a user."
- method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format."
- method_option "id", :aliases => "-i", :type => :boolean, :default => false, :desc => "Specify user via ID instead of screen name."
- method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format."
- method_option "reverse", :aliases => "-r", :type => :boolean, :default => false, :desc => "Reverse the order of the sort."
- method_option "sort", :aliases => "-s", :type => :string, :enum => %w(members mode since slug subscribers), :default => "slug", :desc => "Specify the order of the results.", :banner => "ORDER"
- method_option "unsorted", :aliases => "-u", :type => :boolean, :default => false, :desc => "Output is not sorted."
- def lists(user=nil)
+ desc 'lists [USER]', 'Returns the lists created by a user.'
+ method_option 'csv', :aliases => '-c', :type => :boolean, :default => false, :desc => 'Output in CSV format.'
+ method_option 'id', :aliases => '-i', :type => :boolean, :default => false, :desc => 'Specify user via ID instead of screen name.'
+ method_option 'long', :aliases => '-l', :type => :boolean, :default => false, :desc => 'Output in long format.'
+ method_option 'reverse', :aliases => '-r', :type => :boolean, :default => false, :desc => 'Reverse the order of the sort.'
+ method_option 'sort', :aliases => '-s', :type => :string, :enum => %w(members mode since slug subscribers), :default => 'slug', :desc => 'Specify the order of the results.', :banner => 'ORDER'
+ method_option 'unsorted', :aliases => '-u', :type => :boolean, :default => false, :desc => 'Output is not sorted.'
+ def lists(user = nil)
lists = if user
- require 't/core_ext/string'
- user = if options['id']
- user.to_i
- else
- user.strip_ats
- end
- client.lists(user)
- else
- client.lists
- end
+ require 't/core_ext/string'
+ user = options['id'] ? user.to_i : user.strip_ats
+ client.lists(user)
+ else
+ client.lists
+ end
print_lists(lists)
end
- desc "matrix", "Unfortunately, no one can be told what the Matrix is. You have to see it for yourself."
- def_delegator :"T::Stream.new", :matrix
+ desc 'matrix', 'Unfortunately, no one can be told what the Matrix is. You have to see it for yourself.'
+ def_delegator :"T::Stream.new", :matrix # rubocop:disable SymbolName
- desc "mentions", "Returns the #{DEFAULT_NUM_RESULTS} most recent Tweets mentioning you."
- method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format."
- method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format."
- method_option "number", :aliases => "-n", :type => :numeric, :default => DEFAULT_NUM_RESULTS, :desc => "Limit the number of results."
- method_option "reverse", :aliases => "-r", :type => :boolean, :default => false, :desc => "Reverse the order of the sort."
+ desc 'mentions', "Returns the #{DEFAULT_NUM_RESULTS} most recent Tweets mentioning you."
+ method_option 'csv', :aliases => '-c', :type => :boolean, :default => false, :desc => 'Output in CSV format.'
+ method_option 'long', :aliases => '-l', :type => :boolean, :default => false, :desc => 'Output in long format.'
+ method_option 'number', :aliases => '-n', :type => :numeric, :default => DEFAULT_NUM_RESULTS, :desc => 'Limit the number of results.'
+ method_option 'reverse', :aliases => '-r', :type => :boolean, :default => false, :desc => 'Reverse the order of the sort.'
def mentions
count = options['number'] || DEFAULT_NUM_RESULTS
tweets = collect_with_count(count) do |count_opts|
@@ -490,10 +446,10 @@ def mentions
end
map %w(replies) => :mentions
- desc "open USER", "Opens that user's profile in a web browser."
- method_option "display-uri", :aliases => "-d", :type => :boolean, :default => false, :desc => "Display the requested URL instead of attempting to open it."
- method_option "id", :aliases => "-i", :type => :boolean, :default => false, :desc => "Specify user via ID instead of screen name."
- method_option "status", :aliases => "-s", :type => :boolean, :default => false, :desc => "Specify input as a Twitter status ID instead of a screen name."
+ desc 'open USER', "Opens that user's profile in a web browser."
+ method_option 'display-uri', :aliases => '-d', :type => :boolean, :default => false, :desc => 'Display the requested URL instead of attempting to open it.'
+ method_option 'id', :aliases => '-i', :type => :boolean, :default => false, :desc => 'Specify user via ID instead of screen name.'
+ method_option 'status', :aliases => '-s', :type => :boolean, :default => false, :desc => 'Specify input as a Twitter status ID instead of a screen name.'
def open(user)
require 'launchy'
if options['id']
@@ -508,9 +464,9 @@ def open(user)
end
end
- desc "reply TWEET_ID MESSAGE", "Post your Tweet as a reply directed at another person."
- method_option "all", :aliases => "-a", :type => :boolean, :default => false, :desc => "Reply to all users mentioned in the Tweet."
- method_option "location", :aliases => "-l", :type => :string, :default => "location", :desc => "Add location information. If the optional 'latitude,longitude' parameter is not supplied, looks up location by IP address."
+ desc 'reply TWEET_ID MESSAGE', 'Post your Tweet as a reply directed at another person.'
+ method_option 'all', :aliases => '-a', :type => :boolean, :default => false, :desc => 'Reply to all users mentioned in the Tweet.'
+ method_option 'location', :aliases => '-l', :type => :string, :default => 'location', :desc => "Add location information. If the optional 'latitude,longitude' parameter is not supplied, looks up location by IP address."
def reply(status_id, message)
status = client.status(status_id.to_i, :include_my_retweet => false)
users = Array(status.user.screen_name)
@@ -525,20 +481,20 @@ def reply(status_id, message)
reply = client.update("#{users.join(' ')} #{message}", opts)
say "Reply posted by @#{@rcfile.active_profile[0]} to #{users.join(' ')}."
say
- say "Run `#{File.basename($0)} delete status #{reply.id}` to delete."
+ say "Run `#{File.basename($PROGRAM_NAME)} delete status #{reply.id}` to delete."
end
- desc "report_spam USER [USER...]", "Report users for spam."
- method_option "id", :aliases => "-i", :type => :boolean, :default => false, :desc => "Specify input as Twitter user IDs instead of screen names."
+ desc 'report_spam USER [USER...]', 'Report users for spam.'
+ method_option 'id', :aliases => '-i', :type => :boolean, :default => false, :desc => 'Specify input as Twitter user IDs instead of screen names.'
def report_spam(user, *users)
- users, number = fetch_users(users.unshift(user), options) do |users|
- client.report_spam(users)
+ _, number = fetch_users(users.unshift(user), options) do |users_to_report|
+ client.report_spam(users_to_report)
end
say "@#{@rcfile.active_profile[0]} reported #{pluralize(number, 'user')}."
end
map %w(report reportspam spam) => :report_spam
- desc "retweet TWEET_ID [TWEET_ID...]", "Sends Tweets to your followers."
+ desc 'retweet TWEET_ID [TWEET_ID...]', 'Sends Tweets to your followers.'
def retweet(status_id, *status_ids)
status_ids.unshift(status_id)
status_ids.map!(&:to_i)
@@ -549,99 +505,95 @@ def retweet(status_id, *status_ids)
number = retweets.length
say "@#{@rcfile.active_profile[0]} retweeted #{pluralize(number, 'tweet')}."
say
- say "Run `#{File.basename($0)} delete status #{retweets.map{|tweet| tweet.retweeted_status.id}.join(' ')}` to undo."
+ say "Run `#{File.basename($PROGRAM_NAME)} delete status #{retweets.map { |tweet| tweet.retweeted_status.id}.join(' ')}` to undo."
end
map %w(rt) => :retweet
- desc "retweets [USER]", "Returns the #{DEFAULT_NUM_RESULTS} most recent Retweets by a user."
- method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format."
- method_option "id", :aliases => "-i", :type => :boolean, :default => false, :desc => "Specify user via ID instead of screen name."
- method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format."
- method_option "number", :aliases => "-n", :type => :numeric, :default => DEFAULT_NUM_RESULTS, :desc => "Limit the number of results."
- method_option "reverse", :aliases => "-r", :type => :boolean, :default => false, :desc => "Reverse the order of the sort."
- def retweets(user=nil)
+ desc 'retweets [USER]', "Returns the #{DEFAULT_NUM_RESULTS} most recent Retweets by a user."
+ method_option 'csv', :aliases => '-c', :type => :boolean, :default => false, :desc => 'Output in CSV format.'
+ method_option 'id', :aliases => '-i', :type => :boolean, :default => false, :desc => 'Specify user via ID instead of screen name.'
+ method_option 'long', :aliases => '-l', :type => :boolean, :default => false, :desc => 'Output in long format.'
+ method_option 'number', :aliases => '-n', :type => :numeric, :default => DEFAULT_NUM_RESULTS, :desc => 'Limit the number of results.'
+ method_option 'reverse', :aliases => '-r', :type => :boolean, :default => false, :desc => 'Reverse the order of the sort.'
+ def retweets(user = nil)
count = options['number'] || DEFAULT_NUM_RESULTS
tweets = if user
- require 't/core_ext/string'
- user = if options['id']
- user.to_i
- else
- user.strip_ats
- end
- collect_with_count(count) do |count_opts|
- client.retweeted_by_user(user, count_opts)
- end
- else
- collect_with_count(count) do |count_opts|
- client.retweeted_by_me(count_opts)
- end
- end
+ require 't/core_ext/string'
+ user = options['id'] ? user.to_i : user.strip_ats
+ collect_with_count(count) do |count_opts|
+ client.retweeted_by_user(user, count_opts)
+ end
+ else
+ collect_with_count(count) do |count_opts|
+ client.retweeted_by_me(count_opts)
+ end
+ end
print_tweets(tweets)
end
map %w(rts) => :retweets
- 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."
+ 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
markings = '----|'.chars.cycle.take(140).join
say "#{' ' * options['indent'].to_i}#{markings}"
end
- desc "status TWEET_ID", "Retrieves detailed information about a Tweet."
- method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format."
- method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format."
- def status(status_id)
+ desc 'status TWEET_ID', 'Retrieves detailed information about a Tweet.'
+ method_option 'csv', :aliases => '-c', :type => :boolean, :default => false, :desc => 'Output in CSV format.'
+ method_option 'long', :aliases => '-l', :type => :boolean, :default => false, :desc => 'Output in long format.'
+ def status(status_id) # rubocop:disable CyclomaticComplexity
status = client.status(status_id.to_i, :include_my_retweet => false)
location = if status.place?
- if status.place.name && status.place.attributes && status.place.attributes[:street_address] && status.place.attributes[:locality] && status.place.attributes[:region] && status.place.country
- [status.place.name, status.place.attributes[:street_address], status.place.attributes[:locality], status.place.attributes[:region], status.place.country].join(", ")
- elsif status.place.name && status.place.attributes && status.place.attributes[:locality] && status.place.attributes[:region] && status.place.country
- [status.place.name, status.place.attributes[:locality], status.place.attributes[:region], status.place.country].join(", ")
- elsif status.place.full_name && status.place.attributes && status.place.attributes[:region] && status.place.country
- [status.place.full_name, status.place.attributes[:region], status.place.country].join(", ")
- elsif status.place.full_name && status.place.country
- [status.place.full_name, status.place.country].join(", ")
- elsif status.place.full_name
- status.place.full_name
- else
- status.place.name
- end
- elsif status.geo?
- reverse_geocode(status.geo)
- end
- status_headings = ["ID", "Posted at", "Screen name", "Text", "Retweets", "Favorites", "Source", "Location"]
+ if status.place.name && status.place.attributes && status.place.attributes[:street_address] && status.place.attributes[:locality] && status.place.attributes[:region] && status.place.country
+ [status.place.name, status.place.attributes[:street_address], status.place.attributes[:locality], status.place.attributes[:region], status.place.country].join(', ')
+ elsif status.place.name && status.place.attributes && status.place.attributes[:locality] && status.place.attributes[:region] && status.place.country
+ [status.place.name, status.place.attributes[:locality], status.place.attributes[:region], status.place.country].join(', ')
+ elsif status.place.full_name && status.place.attributes && status.place.attributes[:region] && status.place.country
+ [status.place.full_name, status.place.attributes[:region], status.place.country].join(', ')
+ elsif status.place.full_name && status.place.country
+ [status.place.full_name, status.place.country].join(', ')
+ elsif status.place.full_name
+ status.place.full_name
+ else
+ status.place.name
+ end
+ elsif status.geo?
+ reverse_geocode(status.geo)
+ end
+ status_headings = ['ID', 'Posted at', 'Screen name', 'Text', 'Retweets', 'Favorites', 'Source', 'Location']
if options['csv']
require 'csv'
say status_headings.to_csv
say [status.id, csv_formatted_time(status), status.user.screen_name, decode_full_text(status), status.retweet_count, status.favorite_count, strip_tags(status.source), location].to_csv
elsif options['long']
array = [status.id, ls_formatted_time(status), "@#{status.user.screen_name}", decode_full_text(status).gsub(/\n+/, ' '), status.retweet_count, status.favorite_count, strip_tags(status.source), location]
- format = options['format'] || status_headings.size.times.map{"%s"}
+ format = options['format'] || status_headings.size.times.map { '%s' }
print_table_with_headings([array], status_headings, format)
else
array = []
- array << ["ID", status.id.to_s]
- array << ["Text", decode_full_text(status).gsub(/\n+/, ' ')]
- array << ["Screen name", "@#{status.user.screen_name}"]
- array << ["Posted at", "#{ls_formatted_time(status)} (#{time_ago_in_words(status.created_at)} ago)"]
- array << ["Retweets", number_with_delimiter(status.retweet_count)]
- array << ["Favorites", number_with_delimiter(status.favorite_count)]
- array << ["Source", strip_tags(status.source)]
- array << ["Location", location] unless location.nil?
+ array << ['ID', status.id.to_s]
+ array << ['Text', decode_full_text(status).gsub(/\n+/, ' ')]
+ array << ['Screen name', "@#{status.user.screen_name}"]
+ array << ['Posted at', "#{ls_formatted_time(status)} (#{time_ago_in_words(status.created_at)} ago)"]
+ array << ['Retweets', number_with_delimiter(status.retweet_count)]
+ array << ['Favorites', number_with_delimiter(status.favorite_count)]
+ array << ['Source', strip_tags(status.source)]
+ array << ['Location', location] unless location.nil?
print_table(array)
end
end
- desc "timeline [USER]", "Returns the #{DEFAULT_NUM_RESULTS} most recent Tweets posted by a user."
- method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format."
- method_option "exclude", :aliases => "-e", :type => :string, :enum => %w(replies retweets), :desc => "Exclude certain types of Tweets from the results.", :banner => "TYPE"
- method_option "id", :aliases => "-i", :type => :boolean, :default => false, :desc => "Specify user via ID instead of screen name."
- method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format."
- method_option "max_id", :aliases => "-m", :type => :numeric, :desc => "Returns only the results with an ID less than the specified ID."
- method_option "number", :aliases => "-n", :type => :numeric, :default => DEFAULT_NUM_RESULTS, :desc => "Limit the number of results."
- method_option "reverse", :aliases => "-r", :type => :boolean, :default => false, :desc => "Reverse the order of the sort."
- method_option "since_id", :aliases => "-s", :type => :numeric, :desc => "Returns only the results with an ID greater than the specified ID."
- def timeline(user=nil)
+ desc 'timeline [USER]', "Returns the #{DEFAULT_NUM_RESULTS} most recent Tweets posted by a user."
+ method_option 'csv', :aliases => '-c', :type => :boolean, :default => false, :desc => 'Output in CSV format.'
+ method_option 'exclude', :aliases => '-e', :type => :string, :enum => %w(replies retweets), :desc => 'Exclude certain types of Tweets from the results.', :banner => 'TYPE'
+ method_option 'id', :aliases => '-i', :type => :boolean, :default => false, :desc => 'Specify user via ID instead of screen name.'
+ method_option 'long', :aliases => '-l', :type => :boolean, :default => false, :desc => 'Output in long format.'
+ method_option 'max_id', :aliases => '-m', :type => :numeric, :desc => 'Returns only the results with an ID less than the specified ID.'
+ method_option 'number', :aliases => '-n', :type => :numeric, :default => DEFAULT_NUM_RESULTS, :desc => 'Limit the number of results.'
+ method_option 'reverse', :aliases => '-r', :type => :boolean, :default => false, :desc => 'Reverse the order of the sort.'
+ method_option 'since_id', :aliases => '-s', :type => :numeric, :desc => 'Returns only the results with an ID greater than the specified ID.'
+ def timeline(user = nil) # rubocop:disable CyclomaticComplexity
count = options['number'] || DEFAULT_NUM_RESULTS
opts = {}
opts[:exclude_replies] = true if options['exclude'] == 'replies'
@@ -650,11 +602,7 @@ def timeline(user=nil)
opts[:since_id] = options['since_id'] if options['since_id']
if user
require 't/core_ext/string'
- user = if options['id']
- user.to_i
- else
- user.strip_ats
- end
+ user = options['id'] ? user.to_i : user.strip_ats
tweets = collect_with_count(count) do |count_opts|
client.user_timeline(user, count_opts.merge(opts))
end
@@ -667,35 +615,35 @@ def timeline(user=nil)
end
map %w(tl) => :timeline
- desc "trends [WOEID]", "Returns the top 10 trending topics."
- method_option "exclude-hashtags", :aliases => "-x", :type => :boolean, :default => false, :desc => "Remove all hashtags from the trends list."
- def trends(woe_id=1)
+ desc 'trends [WOEID]', 'Returns the top 10 trending topics.'
+ method_option 'exclude-hashtags', :aliases => '-x', :type => :boolean, :default => false, :desc => 'Remove all hashtags from the trends list.'
+ def trends(woe_id = 1)
opts = {}
- opts.merge!(:exclude => "hashtags") if options['exclude-hashtags']
+ opts.merge!(:exclude => 'hashtags') if options['exclude-hashtags']
trends = client.trends(woe_id, opts)
print_attribute(trends, :name)
end
- desc "trend_locations", "Returns the locations for which Twitter has trending topic information."
- method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format."
- method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format."
- method_option "reverse", :aliases => "-r", :type => :boolean, :default => false, :desc => "Reverse the order of the sort."
- method_option "sort", :aliases => "-s", :type => :string, :enum => %w(country name parent type woeid), :default => "name", :desc => "Specify the order of the results.", :banner => "ORDER"
- method_option "unsorted", :aliases => "-u", :type => :boolean, :default => false, :desc => "Output is not sorted."
- def trend_locations
+ desc 'trend_locations', 'Returns the locations for which Twitter has trending topic information.'
+ method_option 'csv', :aliases => '-c', :type => :boolean, :default => false, :desc => 'Output in CSV format.'
+ method_option 'long', :aliases => '-l', :type => :boolean, :default => false, :desc => 'Output in long format.'
+ method_option 'reverse', :aliases => '-r', :type => :boolean, :default => false, :desc => 'Reverse the order of the sort.'
+ method_option 'sort', :aliases => '-s', :type => :string, :enum => %w(country name parent type woeid), :default => 'name', :desc => 'Specify the order of the results.', :banner => 'ORDER'
+ method_option 'unsorted', :aliases => '-u', :type => :boolean, :default => false, :desc => 'Output is not sorted.'
+ def trend_locations # rubocop:disable CyclomaticComplexity
places = client.trend_locations
places = case options['sort']
- when 'country'
- places.sort_by{|places| places.country.downcase}
- when 'parent'
- places.sort_by{|places| places.parent_id.to_i}
- when 'type'
- places.sort_by{|places| places.place_type.downcase}
- when 'woeid'
- places.sort_by{|places| places.woeid.to_i}
- else
- places.sort_by{|places| places.name.downcase}
- end unless options['unsorted']
+ when 'country'
+ places.sort_by { |place| place.country.downcase }
+ when 'parent'
+ places.sort_by { |place| place.parent_id.to_i }
+ when 'type'
+ places.sort_by { |place| place.place_type.downcase }
+ when 'woeid'
+ places.sort_by { |place| place.woeid.to_i }
+ else
+ places.sort_by { |place| place.name.downcase }
+ end unless options['unsorted']
places.reverse! if options['reverse']
if options['csv']
require 'csv'
@@ -707,7 +655,7 @@ def trend_locations
array = places.map do |place|
[place.woeid, place.parent_id, place.place_type, place.name, place.country]
end
- format = options['format'] || TREND_HEADINGS.size.times.map{"%s"}
+ format = options['format'] || TREND_HEADINGS.size.times.map { '%s' }
print_table_with_headings(array, TREND_HEADINGS, format)
else
print_attribute(places, :name)
@@ -715,110 +663,102 @@ def trend_locations
end
map %w(locations trendlocations) => :trend_locations
- desc "unfollow USER [USER...]", "Allows you to stop following users."
- method_option "id", :aliases => "-i", :type => :boolean, :default => false, :desc => "Specify input as Twitter user IDs instead of screen names."
+ desc 'unfollow USER [USER...]', 'Allows you to stop following users.'
+ method_option 'id', :aliases => '-i', :type => :boolean, :default => false, :desc => 'Specify input as Twitter user IDs instead of screen names.'
def unfollow(user, *users)
- users, number = fetch_users(users.unshift(user), options) do |users|
- client.unfollow(users)
+ unfollowed_users, number = fetch_users(users.unshift(user), options) do |users_to_unfollow|
+ client.unfollow(users_to_unfollow)
end
say "@#{@rcfile.active_profile[0]} is no longer following #{pluralize(number, 'user')}."
say
- say "Run `#{File.basename($0)} follow #{users.map{|user| "@#{user.screen_name}"}.join(' ')}` to follow again."
+ say "Run `#{File.basename($PROGRAM_NAME)} follow #{unfollowed_users.map { |unfollowed_user| "@#{unfollowed_user.screen_name}"}.join(' ')}` to follow again."
end
- desc "update [MESSAGE]", "Post a Tweet."
- method_option "location", :aliases => "-l", :type => :string, :default => "location", :desc => "Add location information. If the optional 'latitude,longitude' parameter is not supplied, looks up location by IP address."
- method_option "file", :aliases => "-f", :type => :string, :desc => "The path to an image to attach to your tweet."
- def update(message=nil)
+ desc 'update [MESSAGE]', 'Post a Tweet.'
+ method_option 'location', :aliases => '-l', :type => :string, :default => 'location', :desc => "Add location information. If the optional 'latitude,longitude' parameter is not supplied, looks up location by IP address."
+ method_option 'file', :aliases => '-f', :type => :string, :desc => 'The path to an image to attach to your tweet.'
+ def update(message = nil)
message = T::Editor.gets if message.nil? || message.empty?
opts = {:trim_user => true}
add_location!(options, opts)
status = if options['file']
- client.update_with_media(message, File.new(File.expand_path(options['file'])), opts)
- else
- client.update(message, opts)
- end
+ client.update_with_media(message, File.new(File.expand_path(options['file'])), opts)
+ else
+ client.update(message, opts)
+ end
say "Tweet posted by @#{@rcfile.active_profile[0]}."
say
- say "Run `#{File.basename($0)} delete status #{status.id}` to delete."
+ say "Run `#{File.basename($PROGRAM_NAME)} delete status #{status.id}` to delete."
end
map %w(post tweet) => :update
- desc "users USER [USER...]", "Returns a list of users you specify."
- method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format."
- method_option "id", :aliases => "-i", :type => :boolean, :default => false, :desc => "Specify input as Twitter user IDs instead of screen names."
- method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format."
- method_option "reverse", :aliases => "-r", :type => :boolean, :default => false, :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, :default => false, :desc => "Output is not sorted."
+ desc 'users USER [USER...]', 'Returns a list of users you specify.'
+ method_option 'csv', :aliases => '-c', :type => :boolean, :default => false, :desc => 'Output in CSV format.'
+ method_option 'id', :aliases => '-i', :type => :boolean, :default => false, :desc => 'Specify input as Twitter user IDs instead of screen names.'
+ method_option 'long', :aliases => '-l', :type => :boolean, :default => false, :desc => 'Output in long format.'
+ method_option 'reverse', :aliases => '-r', :type => :boolean, :default => false, :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, :default => false, :desc => 'Output is not sorted.'
def users(user, *users)
users.unshift(user)
require 't/core_ext/string'
- if options['id']
- users.map!(&:to_i)
- else
- users.map!(&:strip_ats)
- end
+ options['id'] ? users.map!(&:to_i) : users.map!(&:strip_ats)
users = client.users(users)
print_users(users)
end
map %w(stats) => :users
- desc "version", "Show version."
+ desc 'version', 'Show version.'
def version
require 't/version'
say T::Version
end
map %w(-v --version) => :version
- desc "whois USER", "Retrieves profile information for the user."
- method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format."
- method_option "id", :aliases => "-i", :type => :boolean, :default => false, :desc => "Specify user via ID instead of screen name."
- method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format."
- def whois(user)
+ desc 'whois USER', 'Retrieves profile information for the user.'
+ method_option 'csv', :aliases => '-c', :type => :boolean, :default => false, :desc => 'Output in CSV format.'
+ method_option 'id', :aliases => '-i', :type => :boolean, :default => false, :desc => 'Specify user via ID instead of screen name.'
+ method_option 'long', :aliases => '-l', :type => :boolean, :default => false, :desc => 'Output in long format.'
+ def whois(user) # rubocop:disable CyclomaticComplexity
require 't/core_ext/string'
- user = if options['id']
- user.to_i
- else
- user.strip_ats
- end
+ user = options['id'] ? user.to_i : user.strip_ats
user = client.user(user)
require 'htmlentities'
if options['csv'] || options['long']
print_users([user])
else
array = []
- array << ["ID", user.id.to_s]
- array << ["Since", "#{ls_formatted_time(user)} (#{time_ago_in_words(user.created_at)} ago)"]
- array << ["Last update", "#{decode_full_text(user.status).gsub(/\n+/, ' ')} (#{time_ago_in_words(user.status.created_at)} ago)"] unless user.status.nil?
- array << ["Screen name", "@#{user.screen_name}"]
- array << [user.verified ? "Name (Verified)" : "Name", user.name] unless user.name.nil?
- array << ["Tweets", number_with_delimiter(user.statuses_count)]
- array << ["Favorites", number_with_delimiter(user.favorites_count)]
- array << ["Listed", number_with_delimiter(user.listed_count)]
- array << ["Following", number_with_delimiter(user.friends_count)]
- array << ["Followers", number_with_delimiter(user.followers_count)]
- array << ["Bio", user.description.gsub(/\n+/, ' ')] unless user.description.nil?
- array << ["Location", user.location] unless user.location.nil?
- array << ["URL", user.website] unless user.website.nil?
+ array << ['ID', user.id.to_s]
+ array << ['Since', "#{ls_formatted_time(user)} (#{time_ago_in_words(user.created_at)} ago)"]
+ array << ['Last update', "#{decode_full_text(user.status).gsub(/\n+/, ' ')} (#{time_ago_in_words(user.status.created_at)} ago)"] unless user.status.nil?
+ array << ['Screen name', "@#{user.screen_name}"]
+ array << [user.verified ? 'Name (Verified)' : 'Name', user.name] unless user.name.nil?
+ array << ['Tweets', number_with_delimiter(user.statuses_count)]
+ array << ['Favorites', number_with_delimiter(user.favorites_count)]
+ array << ['Listed', number_with_delimiter(user.listed_count)]
+ array << ['Following', number_with_delimiter(user.friends_count)]
+ array << ['Followers', number_with_delimiter(user.followers_count)]
+ array << ['Bio', user.description.gsub(/\n+/, ' ')] unless user.description.nil?
+ array << ['Location', user.location] unless user.location.nil?
+ array << ['URL', user.website] unless user.website.nil?
print_table(array)
end
end
map %w(user) => :whois
- desc "delete SUBCOMMAND ...ARGS", "Delete Tweets, Direct Messages, etc."
+ desc 'delete SUBCOMMAND ...ARGS', 'Delete Tweets, Direct Messages, etc.'
subcommand 'delete', T::Delete
- desc "list SUBCOMMAND ...ARGS", "Do various things with lists."
+ desc 'list SUBCOMMAND ...ARGS', 'Do various things with lists.'
subcommand 'list', T::List
- desc "search SUBCOMMAND ...ARGS", "Search through Tweets."
+ desc 'search SUBCOMMAND ...ARGS', 'Search through Tweets.'
subcommand 'search', T::Search
- desc "set SUBCOMMAND ...ARGS", "Change various account settings."
+ desc 'set SUBCOMMAND ...ARGS', 'Change various account settings.'
subcommand 'set', T::Set
- desc "stream SUBCOMMAND ...ARGS", "Commands for streaming Tweets."
+ desc 'stream SUBCOMMAND ...ARGS', 'Commands for streaming Tweets.'
subcommand 'stream', T::Stream
private
@@ -844,7 +784,7 @@ def generate_authorize_uri(consumer, request_token)
params = request['Authorization'].sub(/^OAuth\s+/, '').split(/,\s+/).map do |param|
key, value = param.split('=')
value =~ /"(.*?)"/
- "#{key}=#{CGI::escape($1)}"
+ "#{key}=#{CGI.escape(Regexp.last_match[1])}"
end.join('&')
"#{Twitter::REST::Client::ENDPOINT}#{request.path}?#{params}"
end
@@ -864,7 +804,7 @@ def location
return @location if @location
require 'geokit'
require 'open-uri'
- ip_address = Kernel::open("http://checkip.dyndns.org/") do |body|
+ ip_address = Kernel.open('http://checkip.dyndns.org/') do |body|
/(?:\d{1,3}\.){3}\d{1,3}/.match(body.read)[0]
end
@location = Geokit::Geocoders::MultiGeocoder.geocode(ip_address)
@@ -874,13 +814,12 @@ def reverse_geocode(geo)
require 'geokit'
geoloc = Geokit::Geocoders::MultiGeocoder.reverse_geocode(geo.coordinates)
if geoloc.city && geoloc.state && geoloc.country
- [geoloc.city, geoloc.state, geoloc.country].join(", ")
+ [geoloc.city, geoloc.state, geoloc.country].join(', ')
elsif geoloc.state && geoloc.country
- [geoloc.state, geoloc.country].join(", ")
+ [geoloc.state, geoloc.country].join(', ')
else
geoloc.country
end
end
-
end
end
View
6 lib/t/collectable.rb
@@ -3,10 +3,9 @@
module T
module Collectable
-
MAX_NUM_RESULTS = 200
- def collect_with_max_id(collection=[], max_id=nil, &block)
+ def collect_with_max_id(collection = [], max_id = nil, &block)
tweets = retryable(:tries => 3, :on => Twitter::Error, :sleep => 0) do
yield(max_id)
end
@@ -29,7 +28,7 @@ def collect_with_count(count, &block)
end.flatten.compact
end
- def collect_with_page(collection=[], page=1, &block)
+ def collect_with_page(collection = [], page = 1, &block)
tweets = retryable(:tries => 3, :on => Twitter::Error, :sleep => 0) do
yield page
end
@@ -37,6 +36,5 @@ def collect_with_page(collection=[], page=1, &block)
collection += tweets
tweets.empty? ? collection.flatten.uniq : collect_with_page(collection, page + 1, &block)
end
-
end
end
View
8 lib/t/core_ext/kernel.rb
@@ -1,15 +1,13 @@
module Kernel
-
- def Bignum(arg, base=0)
+ def Bignum(arg, base = 0) # rubocop:disable MethodName
Integer(arg, base)
end
- def Fixnum(arg, base=0)
+ def Fixnum(arg, base = 0) # rubocop:disable MethodName
Integer(arg, base)
end
- def NilClass(arg)
+ def NilClass(arg) # rubocop:disable MethodName
nil
end
-
end
View
10 lib/t/core_ext/string.rb
@@ -1,17 +1,15 @@
class String
-
def prepend_at
"@#{self}"
end
def strip_ats
- self.tr('@', '')
+ tr('@', '')
end
- alias old_to_i to_i
+ alias_method :old_to_i, :to_i
- def to_i(base=10)
- self.tr(',', '').old_to_i(base)
+ def to_i(base = 10)
+ tr(',', '').old_to_i(base)
end
-
end
View
50 lib/t/delete.rb
@@ -16,20 +16,20 @@ def initialize(*)
super
end
- desc "block USER [USER...]", "Unblock users."
- method_option "id", :aliases => "-i", :type => :boolean, :default => false, :desc => "Specify input as Twitter user IDs instead of screen names."
- method_option "force", :aliases => "-f", :type => :boolean, :default => false
+ desc 'block USER [USER...]', 'Unblock users.'
+ method_option 'id', :aliases => '-i', :type => :boolean, :default => false, :desc => 'Specify input as Twitter user IDs instead of screen names.'
+ method_option 'force', :aliases => '-f', :type => :boolean, :default => false
def block(user, *users)
- users, number = fetch_users(users.unshift(user), options) do |users|
- client.unblock(users)
+ unblocked_users, number = fetch_users(users.unshift(user), options) do |users_to_unblock|
+ client.unblock(users_to_unblock)
end
say "@#{@rcfile.active_profile[0]} unblocked #{pluralize(number, 'user')}."
say
- say "Run `#{File.basename($0)} block #{users.map{|user| "@#{user.screen_name}"}.join(' ')}` to block."
+ say "Run `#{File.basename($PROGRAM_NAME)} block #{unblocked_users.map { |unblocked_user| "@#{unblocked_user.screen_name}"}.join(' ')}` to block."
end
- desc "dm [DIRECT_MESSAGE_ID] [DIRECT_MESSAGE_ID...]", "Delete the last Direct Message sent."
- method_option "force", :aliases => "-f", :type => :boolean, :default => false
+ desc 'dm [DIRECT_MESSAGE_ID] [DIRECT_MESSAGE_ID...]', 'Delete the last Direct Message sent.'
+ method_option 'force', :aliases => '-f', :type => :boolean, :default => false
def dm(direct_message_id, *direct_message_ids)
direct_message_ids.unshift(direct_message_id)
require 't/core_ext/string'
@@ -40,19 +40,18 @@ def dm(direct_message_id, *direct_message_ids)
say "@#{@rcfile.active_profile[0]} deleted the direct message sent to @#{direct_message.recipient.screen_name}: \"#{direct_message.text}\""
end
else
- direct_message_ids.each do |direct_message_id|
- direct_message = client.direct_message(direct_message_id)
+ direct_message_ids.each do |direct_message_id_to_delete|
+ direct_message = client.direct_message(direct_message_id_to_delete)
return unless yes? "Are you sure you want to permanently delete the direct message to @#{direct_message.recipient.screen_name}: \"#{direct_message.text}\"? [y/N]"
- client.destroy_direct_message(direct_message_id)
+ client.destroy_direct_message(direct_message_id_to_delete)
say "@#{@rcfile.active_profile[0]} deleted the direct message sent to @#{direct_message.recipient.screen_name}: \"#{direct_message.text}\""
end
end
-
end
map %w(d m) => :dm
- desc "favorite TWEET_ID [TWEET_ID...]", "Delete favorites."
- method_option "force", :aliases => "-f", :type => :boolean, :default => false
+ desc 'favorite TWEET_ID [TWEET_ID...]', 'Delete favorites.'
+ method_option 'force', :aliases => '-f', :type => :boolean, :default => false
def favorite(status_id, *status_ids)
status_ids.unshift(status_id)
require 't/core_ext/string'
@@ -63,19 +62,19 @@ def favorite(status_id, *status_ids)
say "@#{@rcfile.active_profile[0]} unfavorited @#{status.user.screen_name}'s status: \"#{status.full_text}\""
end
else
- status_ids.each do |status_id|
- status = client.status(status_id, :include_my_retweet => false)
+ status_ids.each do |status_id_to_unfavorite|
+ status = client.status(status_id_to_unfavorite, :include_my_retweet => false)
return unless yes? "Are you sure you want to remove @#{status.user.screen_name}'s status: \"#{status.full_text}\" from your favorites? [y/N]"
- client.unfavorite(status_id)
+ client.unfavorite(status_id_to_unfavorite)
say "@#{@rcfile.active_profile[0]} unfavorited @#{status.user.screen_name}'s status: \"#{status.full_text}\""
end
end
end
map %w(fave favourite) => :favorite
- desc "list LIST", "Delete a list."
- method_option "force", :aliases => "-f", :type => :boolean, :default => false
- method_option "id", :aliases => "-i", :type => :boolean, :default => false, :desc => "Specify list via ID instead of slug."
+ desc 'list LIST', 'Delete a list.'
+ method_option 'force', :aliases => '-f', :type => :boolean, :default => false
+ method_option 'id', :aliases => '-i', :type => :boolean, :default => false, :desc => 'Specify list via ID instead of slug.'
def list(list)
if options['id']
require 't/core_ext/string'
@@ -89,8 +88,8 @@ def list(list)
say "@#{@rcfile.active_profile[0]} deleted the list \"#{list.name}\"."
end
- desc "status TWEET_ID [TWEET_ID...]", "Delete Tweets."
- method_option "force", :aliases => "-f", :type => :boolean, :default => false
+ desc 'status TWEET_ID [TWEET_ID...]', 'Delete Tweets.'
+ method_option 'force', :aliases => '-f', :type => :boolean, :default => false
def status(status_id, *status_ids)
status_ids.unshift(status_id)
require 't/core_ext/string'
@@ -101,15 +100,14 @@ def status(status_id, *status_ids)
say "@#{@rcfile.active_profile[0]} deleted the Tweet: \"#{status.full_text}\""
end
else
- status_ids.each do |status_id|
- status = client.status(status_id, :include_my_retweet => false)
+ status_ids.each do |status_id_to_delete|
+ status = client.status(status_id_to_delete, :include_my_retweet => false)
return unless yes? "Are you sure you want to permanently delete @#{status.user.screen_name}'s status: \"#{status.full_text}\"? [y/N]"
- client.destroy_status(status_id, :trim_user => true)
+ client.destroy_status(status_id_to_delete, :trim_user => true)
say "@#{@rcfile.active_profile[0]} deleted the Tweet: \"#{status.full_text}\""
end
end
end
map %w(post tweet update) => :status
-
end
end
View
4 lib/t/editor.rb
@@ -4,7 +4,6 @@
module T
class Editor
class << self
-
def gets
file = tempfile
edit(file.path)
@@ -15,7 +14,7 @@ def gets
end
def tempfile
- Tempfile.new("TWEET_EDITMSG")
+ Tempfile.new('TWEET_EDITMSG')
end
def edit(path)
@@ -29,7 +28,6 @@ def editor
def system_editor
RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ ? 'notepad' : 'vi'
end
-
end
end
end
View
87 lib/t/list.rb
@@ -24,92 +24,92 @@ def initialize(*)
super
end
- desc "add LIST USER [USER...]", "Add members to a list."
- method_option "id", :aliases => "-i", :type => :boolean, :default => false, :desc => "Specify input as Twitter user IDs instead of screen names."
+ desc 'add LIST USER [USER...]', 'Add members to a list.'
+ method_option 'id', :aliases => '-i', :type => :boolean, :default => false, :desc => 'Specify input as Twitter user IDs instead of screen names.'
def add(list, user, *users)
- users, number = fetch_users(users.unshift(user), options) do |users|
- client.add_list_members(list, users)
- users
+ added_users, number = fetch_users(users.unshift(user), options) do |users_to_add|
+ client.add_list_members(list, users_to_add)
+ users_to_add
end
say "@#{@rcfile.active_profile[0]} added #{pluralize(number, 'member')} to the list \"#{list}\"."
say
if options['id']
- say "Run `#{File.basename($0)} list remove --id #{list} #{users.join(' ')}` to undo."
+ say "Run `#{File.basename($PROGRAM_NAME)} list remove --id #{list} #{added_users.join(' ')}` to undo."
else
- say "Run `#{File.basename($0)} list remove #{list} #{users.map{|user| "@#{user}"}.join(' ')}` to undo."
+ say "Run `#{File.basename($PROGRAM_NAME)} list remove #{list} #{added_users.map { |added_user| "@#{added_user}"}.join(' ')}` to undo."
end
end
- desc "create LIST [DESCRIPTION]", "Create a new list."
- method_option "private", :aliases => "-p", :type => :boolean
- def create(list, description=nil)
+ desc 'create LIST [DESCRIPTION]', 'Create a new list.'
+ method_option 'private', :aliases => '-p', :type => :boolean
+ def create(list, description = nil)
opts = description ? {:description => description} : {}
opts.merge!(:mode => 'private') if options['private']
client.create_list(list, opts)
say "@#{@rcfile.active_profile[0]} created the list \"#{list}\"."
end
- desc "information [USER/]LIST", "Retrieves detailed information about a Twitter list."
- method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format."
+ desc 'information [USER/]LIST', 'Retrieves detailed information about a Twitter list.'
+ method_option 'csv', :aliases => '-c', :type => :boolean, :default => false, :desc => 'Output in CSV format.'
def information(list)
owner, list = extract_owner(list, options)
list = client.list(owner, list)
if options['csv']
require 'csv'
- say ["ID", "Description", "Slug", "Screen name", "Created at", "Members", "Subscribers", "Following", "Mode", "URL"].to_csv
+ say ['ID', 'Description', 'Slug', 'Screen name', 'Created at', 'Members', 'Subscribers', 'Following', 'Mode', 'URL'].to_csv
say [list.id, list.description, list.slug, list.user.screen_name, csv_formatted_time(list), list.member_count, list.subscriber_count, list.following?, list.mode, list.uri].to_csv
else
array = []
- array << ["ID", list.id.to_s]
- array << ["Description", list.description] unless list.description.nil?
- array << ["Slug", list.slug]
- array << ["Screen name", "@#{list.user.screen_name}"]
- array << ["Created at", "#{ls_formatted_time(list)} (#{time_ago_in_words(list.created_at)} ago)"]
- array << ["Members", number_with_delimiter(list.member_count)]
- array << ["Subscribers", number_with_delimiter(list.subscriber_count)]
- array << ["Status", list.following ? "Following" : "Not following"]
- array << ["Mode", list.mode]
- array << ["URL", list.uri]
+ array << ['ID', list.id.to_s]
+ array << ['Description', list.description] unless list.description.nil?
+ array << ['Slug', list.slug]
+ array << ['Screen name', "@#{list.user.screen_name}"]
+ array << ['Created at', "#{ls_formatted_time(list)} (#{time_ago_in_words(list.created_at)} ago)"]
+ array << ['Members', number_with_delimiter(list.member_count)]
+ array << ['Subscribers', number_with_delimiter(list.subscriber_count)]
+ array << ['Status', list.following ? 'Following' : 'Not following']
+ array << ['Mode', list.mode]
+ array << ['URL', list.uri]
print_table(array)
end
end
map %w(details) => :information
- desc "members [USER/]LIST", "Returns the members of a Twitter list."
- method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format."
- method_option "id", :aliases => "-i", :type => :boolean, :default => false, :desc => "Specify user via ID instead of screen name."
- method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format."
- method_option "reverse", :aliases => "-r", :type => :boolean, :default => false, :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, :default => false, :desc => "Output is not sorted."
+ desc 'members [USER/]LIST', 'Returns the members of a Twitter list.'
+ method_option 'csv', :aliases => '-c', :type => :boolean, :default => false, :desc => 'Output in CSV format.'
+ method_option 'id', :aliases => '-i', :type => :boolean, :default => false, :desc => 'Specify user via ID instead of screen name.'
+ method_option 'long', :aliases => '-l', :type => :boolean, :default => false, :desc => 'Output in long format.'
+ method_option 'reverse', :aliases => '-r', :type => :boolean, :default => false, :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, :default => false, :desc => 'Output is not sorted.'
def members(list)
owner, list = extract_owner(list, options)
users = client.list_members(owner, list).to_a
print_users(users)
end
- desc "remove LIST USER [USER...]", "Remove members from a list."
- method_option "id", :aliases => "-i", :type => :boolean, :default => false, :desc => "Specify input as Twitter user IDs instead of screen names."
+ desc 'remove LIST USER [USER...]', 'Remove members from a list.'
+ method_option 'id', :aliases => '-i', :type => :boolean, :default => false, :desc => 'Specify input as Twitter user IDs instead of screen names.'
def remove(list, user, *users)
- users, number = fetch_users(users.unshift(user), options) do |users|
- client.remove_list_members(list, users)
- users
+ removed_users, number = fetch_users(users.unshift(user), options) do |users_to_remove|
+ client.remove_list_members(list, users_to_remove)
+ users_to_remove
end
say "@#{@rcfile.active_profile[0]} removed #{pluralize(number, 'member')} from the list \"#{list}\"."
say
if options['id']
- say "Run `#{File.basename($0)} list add --id #{list} #{users.join(' ')}` to undo."
+ say "Run `#{File.basename($PROGRAM_NAME)} list add --id #{list} #{removed_users.join(' ')}` to undo."
else
- say "Run `#{File.basename($0)} list add #{list} #{users.map{|user| "@#{user}"}.join(' ')}` to undo."
+ say "Run `#{File.basename($PROGRAM_NAME)} list add #{list} #{removed_users.map { |removed_user| "@#{removed_user}"}.join(' ')}` to undo."
end
end
- desc "timeline [USER/]LIST", "Show tweet timeline for members of the specified list."
- method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format."
- method_option "id", :aliases => "-i", :type => :boolean, :default => false, :desc => "Specify user via ID instead of screen name."
- method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format."
- method_option "number", :aliases => "-n", :type => :numeric, :default => DEFAULT_NUM_RESULTS, :desc => "Limit the number of results."
- method_option "reverse", :aliases => "-r", :type => :boolean, :default => false, :desc => "Reverse the order of the sort."
+ desc 'timeline [USER/]LIST', 'Show tweet timeline for members of the specified list.'
+ method_option 'csv', :aliases => '-c', :type => :boolean, :default => false, :desc => 'Output in CSV format.'
+ method_option 'id', :aliases => '-i', :type => :boolean, :default => false, :desc => 'Specify user via ID instead of screen name.'
+ method_option 'long', :aliases => '-l', :type => :boolean, :default => false, :desc => 'Output in long format.'
+ method_option 'number', :aliases => '-n', :type => :numeric, :default => DEFAULT_NUM_RESULTS, :desc => 'Limit the number of results.'
+ method_option 'reverse', :aliases => '-r', :type => :boolean, :default => false, :desc => 'Reverse the order of the sort.'
def timeline(list)
owner, list = extract_owner(list, options)
count = options['number'] || DEFAULT_NUM_RESULTS
@@ -119,6 +119,5 @@ def timeline(list)
print_tweets(tweets)
end
map %w(tl) => :timeline
-
end
end
View
91 lib/t/printable.rb
@@ -1,9 +1,9 @@
module T
module Printable
- LIST_HEADINGS = ["ID", "Created at", "Screen name", "Slug", "Members", "Subscribers", "Mode", "Description"]
- TWEET_HEADINGS = ["ID", "Posted at", "Screen name", "Text"]
- USER_HEADINGS = ["ID", "Since", "Last tweeted at", "Tweets", "Favorites", "Listed", "Following", "Followers", "Screen name", "Name", "Verified", "Protected", "Bio", "Status", "Location", "URL"]
- MONTH_IN_SECONDS = 2592000
+ LIST_HEADINGS = ['ID', 'Created at', 'Screen name', 'Slug', 'Members', 'Subscribers', 'Mode', 'Description']
+ TWEET_HEADINGS = ['ID'</