class T::Search
Constants
- DEFAULT_NUM_RESULTS
- MAX_NUM_RESULTS
- MAX_SEARCH_RESULTS
Public Class Methods
new(*)
click to toggle source
Calls superclass method
# File lib/t/search.rb, line 22 def initialize(*) @rcfile = T::RCFile.instance super end
Public Instance Methods
all(query)
click to toggle source
# File lib/t/search.rb, line 33 def all(query) count = options["number"] || DEFAULT_NUM_RESULTS opts = {count: MAX_SEARCH_RESULTS} opts[:include_entities] = !!options["decode_uris"] tweets = client.search(query, opts).take(count) tweets.reverse! if options["reverse"] 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, options["decode_uris"])].to_csv end elsif options["long"] array = tweets.collect do |tweet| [tweet.id, ls_formatted_time(tweet), "@#{tweet.user.screen_name}", decode_full_text(tweet, options["decode_uris"]).gsub(/\n+/, " ")] end format = options["format"] || Array.new(TWEET_HEADINGS.size) { "%s" } print_table_with_headings(array, TWEET_HEADINGS, format) else say unless tweets.empty? tweets.each do |tweet| print_message(tweet.user.screen_name, decode_full_text(tweet, options["decode_uris"])) end end end
favorites(*args)
click to toggle source
# File lib/t/search.rb, line 65 def favorites(*args) query = args.pop user = args.pop 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? client.favorites(user, opts) end else tweets = collect_with_max_id do |max_id| opts[:max_id] = max_id unless max_id.nil? client.favorites(opts) end end tweets = tweets.select do |tweet| /#{query}/i.match(tweet.full_text) end print_tweets(tweets) end
list(user_list, query)
click to toggle source
# File lib/t/search.rb, line 96 def list(user_list, query) owner, list_name = extract_owner(user_list, options) opts = {count: MAX_NUM_RESULTS} 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_name, opts) end tweets = tweets.select do |tweet| /#{query}/i.match(tweet.full_text) end print_tweets(tweets) end
mentions(query)
click to toggle source
# File lib/t/search.rb, line 115 def mentions(query) opts = {count: MAX_NUM_RESULTS} 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
retweets(*args)
click to toggle source
# File lib/t/search.rb, line 135 def retweets(*args) query = args.pop user = args.pop 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? client.retweeted_by_user(user, opts) end else tweets = collect_with_max_id do |max_id| opts[:max_id] = max_id unless max_id.nil? client.retweeted_by_me(opts) end end tweets = tweets.select do |tweet| /#{query}/i.match(tweet.full_text) end print_tweets(tweets) end
timeline(*args)
click to toggle source
# File lib/t/search.rb, line 169 def timeline(*args) query = args.pop user = args.pop opts = {count: MAX_NUM_RESULTS} 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" 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? client.user_timeline(user, opts) end else tweets = collect_with_max_id do |max_id| opts[:max_id] = max_id unless max_id.nil? client.home_timeline(opts) end end tweets = tweets.select do |tweet| /#{query}/i.match(tweet.full_text) end print_tweets(tweets) end
users(query)
click to toggle source
# File lib/t/search.rb, line 205 def users(query) users = collect_with_page do |page| client.user_search(query, page:) end print_users(users) end