lib/t/search.rb in t-2.2.0 vs lib/t/search.rb in t-2.2.1
- old
+ new
@@ -30,19 +30,18 @@
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
def all(query)
count = options['number'] || DEFAULT_NUM_RESULTS
opts = {:count => MAX_SEARCH_RESULTS}
- opts[:include_entities] = 1 if options['decode_uris']
+ opts[:include_entities] = !!options['decode_uris']
tweets = client.search(query, opts).take(count)
tweets.reverse! if options['reverse']
- require 'htmlentities'
if options['csv']
require 'csv'
say TWEET_HEADINGS.to_csv unless tweets.empty?
tweets.each do |tweet|
- say [tweet.id, csv_formatted_time(tweet), tweet.user.screen_name, decode_full_text(tweet)].to_csv
+ say [tweet.id, csv_formatted_time(tweet), tweet.user.screen_name, decode_full_text(tweet, options['decode_uris'])].to_csv
end
elsif options['long']
array = tweets.map do |tweet|
[tweet.id, ls_formatted_time(tweet), "@#{tweet.user.screen_name}", decode_full_text(tweet, options['decode_uris']).gsub(/\n+/, ' ')]
end
@@ -60,14 +59,14 @@
method_option 'csv', :aliases => '-c', :type => :boolean, :default => false, :desc => 'Output in CSV format.'
method_option 'decode_uris', :aliases => '-d', :type => :boolean, :default => false, :desc => 'Decodes t.co URLs into their original form.'
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 favorites(*args)
- opts = {:count => MAX_NUM_RESULTS}
query = args.pop
user = args.pop
- opts[:include_entities] = 1 if options['decode_uris']
+ opts = {:count => MAX_NUM_RESULTS}
+ opts[:include_entities] = !!options['decode_uris']
if user
require 't/core_ext/string'
user = options['id'] ? user.to_i : user.strip_ats
tweets = collect_with_max_id do |max_id|
opts[:max_id] = max_id unless max_id.nil?
@@ -82,21 +81,21 @@
tweets = tweets.select do |tweet|
/#{query}/i.match(tweet.full_text)
end
print_tweets(tweets)
end
- map %w(faves) => :favorites
+ map %w[faves] => :favorites
desc 'list [USER/]LIST QUERY', 'Returns Tweets on a list that match the specified query.'
method_option 'csv', :aliases => '-c', :type => :boolean, :default => false, :desc => 'Output in CSV format.'
+ method_option 'decode_uris', :aliases => '-d', :type => :boolean, :default => false, :desc => 'Decodes t.co URLs into their original form.'
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 'decode_uris', :aliases => '-d', :type => :boolean, :default => false, :desc => 'Decodes t.co URLs into their original form.'
def list(list, query)
owner, list = extract_owner(list, options)
opts = {:count => MAX_NUM_RESULTS}
- opts[:include_entities] = 1 if options['decode_uris']
+ opts[:include_entities] = !!options['decode_uris']
tweets = collect_with_max_id do |max_id|
opts[:max_id] = max_id unless max_id.nil?
client.list_timeline(owner, list, opts)
end
tweets = tweets.select do |tweet|
@@ -105,36 +104,36 @@
print_tweets(tweets)
end
desc 'mentions QUERY', 'Returns Tweets mentioning you that match the specified query.'
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 'decode_uris', :aliases => '-d', :type => :boolean, :default => false, :desc => 'Decodes t.co URLs into their original form.'
+ method_option 'long', :aliases => '-l', :type => :boolean, :default => false, :desc => 'Output in long format.'
def mentions(query)
opts = {:count => MAX_NUM_RESULTS}
- opts[:include_entities] = 1 if options['decode_uris']
+ opts[:include_entities] = !!options['decode_uris']
tweets = collect_with_max_id do |max_id|
opts[:max_id] = max_id unless max_id.nil?
client.mentions(opts)
end
tweets = tweets.select do |tweet|
/#{query}/i.match(tweet.full_text)
end
print_tweets(tweets)
end
- map %w(replies) => :mentions
+ map %w[replies] => :mentions
desc 'retweets [USER] QUERY', "Returns Tweets you've retweeted that match the specified query."
method_option 'csv', :aliases => '-c', :type => :boolean, :default => false, :desc => 'Output in CSV format.'
+ method_option 'decode_uris', :aliases => '-d', :type => :boolean, :default => false, :desc => 'Decodes t.co URLs into their original form.'
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 'decode_uris', :aliases => '-d', :type => :boolean, :default => false, :desc => 'Decodes t.co URLs into their original form.'
def retweets(*args)
- opts = {:count => MAX_NUM_RESULTS}
query = args.pop
user = args.pop
- opts[:include_entities] = 1 if options['decode_uris']
+ opts = {:count => MAX_NUM_RESULTS}
+ opts[:include_entities] = !!options['decode_uris']
if user
require 't/core_ext/string'
user = options['id'] ? user.to_i : user.strip_ats
tweets = collect_with_max_id do |max_id|
opts[:max_id] = max_id unless max_id.nil?
@@ -149,26 +148,26 @@
tweets = tweets.select do |tweet|
/#{query}/i.match(tweet.full_text)
end
print_tweets(tweets)
end
- map %w(rts) => :retweets
+ map %w[rts] => :retweets
desc 'timeline [USER] QUERY', 'Returns Tweets in your timeline that match the specified query.'
method_option 'csv', :aliases => '-c', :type => :boolean, :default => false, :desc => 'Output in CSV format.'
method_option 'decode_uris', :aliases => '-d', :type => :boolean, :default => false, :desc => 'Decodes t.co URLs into their original form.'
- method_option 'exclude', :aliases => '-e', :type => :string, :enum => %w(replies retweets), :desc => 'Exclude certain types of Tweets from the results.', :banner => 'TYPE'
+ 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 'since_id', :aliases => '-s', :type => :numeric, :desc => 'Returns only the results with an ID greater than the specified ID.'
def timeline(*args)
query = args.pop
user = args.pop
opts = {:count => MAX_NUM_RESULTS}
- opts[:include_entities] = 1 if options['decode_uris']
opts[:exclude_replies] = true if options['exclude'] == 'replies'
+ opts[:include_entities] = !!options['decode_uris']
opts[:include_rts] = false if options['exclude'] == 'retweets'
opts[:max_id] = options['max_id'] if options['max_id']
opts[:since_id] = options['since_id'] if options['since_id']
if user
require 't/core_ext/string'
@@ -186,16 +185,16 @@
tweets = tweets.select do |tweet|
/#{query}/i.match(tweet.full_text)
end
print_tweets(tweets)
end
- map %w(tl) => :timeline
+ map %w[tl] => :timeline
desc 'users QUERY', 'Returns users that match the specified query.'
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(favorites followers friends listed screen_name since tweets tweeted), :default => 'screen_name', :desc => 'Specify the order of the results.', :banner => 'ORDER'
+ 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(query)
users = collect_with_page do |page|
client.user_search(query, :page => page)
end