lib/t/search.rb in t-1.7.2 vs lib/t/search.rb in t-2.0.0

- old
+ new

@@ -24,51 +24,50 @@ end desc "all QUERY", "Returns the #{DEFAULT_NUM_RESULTS} most recent Tweets 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_urls", :aliases => "-d", :type => :boolean, :default => false, :desc => "Decodes t.co URLs into their original form." + method_option "decode_uris", :aliases => "-d", :type => :boolean, :default => false, :desc => "Decodes t.co URLs into their original form." method_option "number", :aliases => "-n", :type => :numeric, :default => DEFAULT_NUM_RESULTS def all(query) count = options['number'] || DEFAULT_NUM_RESULTS tweets = collect_with_count(count) do |count_opts| - count_opts[:include_entities] = 1 if options['decode_urls'] - client.search(query, count_opts).results + count_opts[:include_entities] = 1 if options['decode_uris'] + client.search(query, count_opts).to_a end tweets.reverse! if options['reverse'] require 'htmlentities' if options['csv'] require 'csv' - require 'fastercsv' unless Array.new.respond_to?(:to_csv) say TWEET_HEADINGS.to_csv unless tweets.empty? tweets.each do |tweet| - say [tweet.id, csv_formatted_time(tweet), tweet.from_user, decode_full_text(tweet)].to_csv + say [tweet.id, csv_formatted_time(tweet), tweet.user.screen_name, decode_full_text(tweet)].to_csv end elsif options['long'] array = tweets.map do |tweet| - [tweet.id, ls_formatted_time(tweet), "@#{tweet.from_user}", decode_full_text(tweet, options['decode_urls']).gsub(/\n+/, ' ')] + [tweet.id, ls_formatted_time(tweet), "@#{tweet.user.screen_name}", decode_full_text(tweet, options['decode_uris']).gsub(/\n+/, ' ')] end format = options['format'] || TWEET_HEADINGS.size.times.map{"%s"} print_table_with_headings(array, TWEET_HEADINGS, format) else say unless tweets.empty? tweets.each do |tweet| - print_message(tweet.from_user, decode_full_text(tweet, options['decode_urls'])) + print_message(tweet.user.screen_name, decode_full_text(tweet, options['decode_uris'])) end end end desc "favorites [USER] QUERY", "Returns Tweets you've favorited that match the specified query." 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 "decode_urls", :aliases => "-d", :type => :boolean, :default => false, :desc => "Decodes t.co URLs into their original form." + 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 favorites(*args) opts = {:count => MAX_NUM_RESULTS} query = args.pop user = args.pop - opts[:include_entities] = 1 if options['decode_urls'] + opts[:include_entities] = 1 if options['decode_uris'] if user require 't/core_ext/string' user = if options['id'] user.to_i else @@ -93,15 +92,15 @@ desc "list [USER/]LIST QUERY", "Returns Tweets on a list that match specified query." 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 "decode_urls", :aliases => "-d", :type => :boolean, :default => false, :desc => "Decodes t.co URLs into their original form." + 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_urls'] + opts[:include_entities] = 1 if 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| @@ -111,14 +110,14 @@ 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_urls", :aliases => "-d", :type => :boolean, :default => false, :desc => "Decodes t.co URLs into their original form." + method_option "decode_uris", :aliases => "-d", :type => :boolean, :default => false, :desc => "Decodes t.co URLs into their original form." def mentions(query) opts = {:count => MAX_NUM_RESULTS} - opts[:include_entities] = 1 if options['decode_urls'] + opts[:include_entities] = 1 if 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| @@ -130,16 +129,16 @@ 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 "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_urls", :aliases => "-d", :type => :boolean, :default => false, :desc => "Decodes t.co URLs into their original form." + 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_urls'] + opts[:include_entities] = 1 if options['decode_uris'] if user require 't/core_ext/string' user = if options['id'] user.to_i else @@ -162,20 +161,20 @@ end 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_urls", :aliases => "-d", :type => :boolean, :default => false, :desc => "Decodes t.co URLs into their original form." + 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 "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_urls'] + opts[:include_entities] = 1 if options['decode_uris'] opts[:exclude_replies] = true if options['exclude'] == 'replies' 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