class Redchick::Cli
Public Class Methods
new(config)
click to toggle source
# File lib/redchick.rb, line 18 def initialize(config) @config = config current_user = @config[:current_user] token = @config[:users][current_user.to_sym][:oauth_token] secret = @config[:users][current_user.to_sym][:oauth_token_secret] @client = Twitter::REST::Client.new do |conf| conf.consumer_key = CONSUMER_KEY conf.consumer_secret = CONSUMER_SECRET conf.access_token = token conf.access_token_secret = secret end @timeline_opts = { count: @config[:count] } end
Public Instance Methods
block(users)
click to toggle source
# File lib/redchick.rb, line 202 def block(users) users.each { |u| @client.block u } end
Also aliased as: bl
config()
click to toggle source
# File lib/redchick.rb, line 69 def config puts @config end
delete(ids)
click to toggle source
# File lib/redchick.rb, line 122 def delete(ids) ids.each { |id| @client.destroy_status id } end
Also aliased as: del
exit()
click to toggle source
# File lib/redchick.rb, line 64 def exit exit! end
Also aliased as: quit
follow(users)
click to toggle source
# File lib/redchick.rb, line 192 def follow(users) users.each { |u| @client.follow u } end
Also aliased as: f
help()
click to toggle source
# File lib/redchick.rb, line 81 def help help_text = <<-'EOS' explore commands: home mentions likes view <screen name> whois <screen name> search <query> tweet commands: tweet reply <tweet id> delete <tweet id> like <tweet id> retweet <tweet id> open <tweet id> friends and followers commands: ls fl,fr follow <screen name> unfollow <screen name> list commands: lists list <list name> EOS puts help_text end
Also aliased as: h
home()
click to toggle source
# File lib/redchick.rb, line 140 def home @client.home_timeline(@timeline_opts).each do |t| show_tweet(t) end end
layout()
click to toggle source
# File lib/redchick.rb, line 73 def layout puts @config[:layout] end
like(ids)
click to toggle source
# File lib/redchick.rb, line 127 def like(ids) ids.each { |i| @client.favorite i } end
likes()
click to toggle source
# File lib/redchick.rb, line 152 def likes @client.favorites(count: @config[:count]).each do |t| show_tweet(t) end end
list(arg)
click to toggle source
# File lib/redchick.rb, line 213 def list(arg) @client.list_timeline(arg[0]).each do |t| show_tweet(t) end end
lists()
click to toggle source
# File lib/redchick.rb, line 207 def lists @client.owned_lists.each do |l| puts l.name end end
ls(arg)
click to toggle source
# File lib/redchick.rb, line 181 def ls(arg) case arg[0] when 'fl' @client.followers.each { |user| puts user.screen_name } when 'fr' @client.friends.each { |user| puts user.screen_name } else puts 'error' end end
mentions()
click to toggle source
# File lib/redchick.rb, line 146 def mentions @client.mentions_timeline(@timeline_opts).each do |t| show_tweet(t) end end
open(ids)
click to toggle source
# File lib/redchick.rb, line 135 def open(ids) ids.each { |id| system "open #{@client.status(id).uri}" } end
Also aliased as: o
reply(id_and_str)
click to toggle source
# File lib/redchick.rb, line 114 def reply(id_and_str) id = id_and_str[0] str = id_and_str[1] target = @client.status(id) @client.update("@#{target.user.screen_name} #{str}", in_reply_to_status: target) end
Also aliased as: rep
retweet(ids)
click to toggle source
# File lib/redchick.rb, line 131 def retweet(ids) ids.each { |i| @client.retweet i } end
search(query)
click to toggle source
# File lib/redchick.rb, line 174 def search(query) @client.search("#{query}").take(@config[:count]).each do |t| show_tweet(t) end end
Also aliased as: s
show_tweet(t)
click to toggle source
# File lib/redchick.rb, line 219 def show_tweet(t) puts Redchick::Layout.send(@config[:layout], t) end
start()
click to toggle source
# File lib/redchick.rb, line 36 def start puts "redchick version: #{Redchick::VERSION::STRING}" client_methods = Redchick::Cli.instance_methods(false) commands = client_methods.map(&:to_s) comp = proc { |s| commands.grep(/^#{Regexp.escape(s)}/) } Readline.completion_proc = comp while buf = Readline.readline("\e[31m>\e[0m ", true) begin cmd, *vals = buf.split(' ') if cmd cmd = cmd.to_sym if client_methods.include?(cmd) if vals.empty? send(cmd) else send(cmd, vals) end else puts 'no command' puts 'please use help' end end rescue puts 'error' end end end
tweet(vals)
click to toggle source
# File lib/redchick.rb, line 109 def tweet(vals) @client.update(vals.join(' ')) end
Also aliased as: t
unfollow(users)
click to toggle source
# File lib/redchick.rb, line 197 def unfollow(users) users.each { |u| @client.unfollow u } end
Also aliased as: uf
version()
click to toggle source
# File lib/redchick.rb, line 77 def version puts Redchick::VERSION::STRING end
view(username)
click to toggle source
# File lib/redchick.rb, line 158 def view(username) @client.user_timeline(username, @timeline_opts).each do |t| show_tweet(t) end end
whois(username)
click to toggle source
# File lib/redchick.rb, line 164 def whois(username) user = @client.user(username) puts "name: #{user.name}" puts "description: #{user.description}" puts "tweets: #{user.statuses_count}" puts "followers: #{user.followers_count}" puts "friends: #{user.friends_count}" puts "location: #{user.location}" end