Class: Tweetline::CLI
- Inherits:
-
Thor
- Object
- Thor
- Tweetline::CLI
- Defined in:
- lib/tweetline/cli.rb
Instance Method Summary collapse
- #cat(twitter_id = "") ⇒ Object
- #follow(screen_name = "") ⇒ Object
- #grep(pattern) ⇒ Object
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #json ⇒ Object
- #ls(screen_name = "") ⇒ Object
- #retweet(twitter_id = "") ⇒ Object
- #rm(twitter_id = "") ⇒ Object
- #say ⇒ Object
- #tail ⇒ Object
- #unfollow(screen_name = "") ⇒ Object
- #update(status) ⇒ Object
- #yaml ⇒ Object
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
3 4 5 6 7 |
# File 'lib/tweetline/cli.rb', line 3 def initialize(*) super Tweetline.configure_twitter Tweetline.configure_pipes end |
Instance Method Details
#cat(twitter_id = "") ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/tweetline/cli.rb', line 12 def cat(twitter_id = "") if twitter_id.strip.length > 0 tweet = Twitter.status(ARGV[1]) Tweetline.cat_tweet(tweet.id, tweet.created_at, tweet.user.name, tweet.user.screen_name, tweet.text) else Tweetline.each_tweet do |tweet| Tweetline.cat_tweet(tweet["id"], tweet["created_at"], tweet["name"], tweet["screen_name"], tweet["text"]) end end end |
#follow(screen_name = "") ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/tweetline/cli.rb', line 24 def follow(screen_name = "") if screen_name.strip.length > 0 Twitter.follow(screen_name) else Tweetline.each_tweet do |tweet| Twitter.follow(tweet["screen_name"]) puts "Followed -> #{tweet["screen_name"]}" unless Twitter.is_piped_to_tweetline? end end end |
#grep(pattern) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/tweetline/cli.rb', line 36 def grep(pattern) Tweetline.each_tweet do |tweet| regex = Regexp.new(pattern) if regex =~ tweet["name"] or regex =~ tweet["screen_name"] or regex =~ tweet["text"] Tweetline.put_tweet(tweet["id"], tweet["created_at"], tweet["name"], tweet["screen_name"], tweet["text"]) end end end |
#json ⇒ Object
46 47 48 49 50 |
# File 'lib/tweetline/cli.rb', line 46 def json Tweetline.each_tweet do |tweet| puts tweet.to_json end end |
#ls(screen_name = "") ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/tweetline/cli.rb', line 53 def ls(screen_name = "") = {:count => 10} [:screen_name] = screen_name if screen_name.strip.length > 0 Tweetline.each_tweet() do |tweet| Tweetline.put_tweet(tweet["id"], tweet["created_at"], tweet["name"], tweet["screen_name"], tweet["text"]) end end |
#retweet(twitter_id = "") ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/tweetline/cli.rb', line 62 def retweet(twitter_id = "") if twitter_id.strip.length > 0 Twitter.retweet(twitter_id) else Tweetline.each_tweet do |tweet| Twitter.retweet(tweet["id"]) puts "Retweeted:" unless Twitter.is_piped_to_tweetline? Twitter.put_tweet(tweet["id"], tweet["created_at"], tweet["name"], tweet["screen_name"], tweet["text"]) end end end |
#rm(twitter_id = "") ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/tweetline/cli.rb', line 75 def rm(twitter_id = "") if twitter_id.strip.length > 0 Twitter.status_destroy(twitter_id) else Tweetline.each_tweet do |tweet| Twitter.status_destroy(tweet["id"]) puts "Removed:" unless Twitter.is_piped_to_tweetline? Twitter.put_tweet(tweet["id"], tweet["created_at"], tweet["name"], tweet["screen_name"], tweet["text"]) end end end |
#say ⇒ Object
88 89 90 91 92 |
# File 'lib/tweetline/cli.rb', line 88 def say Tweetline.each_tweet(:count => 1) do |tweet| Tweetline.say_tweet(tweet["id"], tweet["created_at"], tweet["name"], tweet["screen_name"], tweet["text"]) end end |
#tail ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/tweetline/cli.rb', line 97 def tail opts = .dup Signal.trap("SIGINT") do exit! end previous_id = "1" begin tweets = Twitter.home_timeline(:count => opts[:number], :since_id => previous_id) rescue [] tweets.reverse_each do |tweet| Tweetline.put_tweet(tweet.id, tweet.created_at, tweet.user.name, tweet.user.screen_name, tweet.text) previous_id = tweet.id end sleep(30) if opts[:follow] end while opts[:follow] end |
#unfollow(screen_name = "") ⇒ Object
118 119 120 121 122 123 124 125 126 127 |
# File 'lib/tweetline/cli.rb', line 118 def unfollow(screen_name = "") if screen_name.strip.length > 0 Twitter.unfollow(screen_name) else Tweetline.each_tweet do |tweet| Twitter.unfollow(tweet["screen_name"]) puts "Followed -> #{tweet["screen_name"]}" unless Twitter.is_piped_to_tweetline? end end end |
#update(status) ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/tweetline/cli.rb', line 130 def update(status) if status.length > 140 puts "" puts "This status is too long." puts "" puts " #{status[0..139]}" puts "" else Twitter.update(status) end end |
#yaml ⇒ Object
143 144 145 146 147 |
# File 'lib/tweetline/cli.rb', line 143 def yaml Tweetline.each_tweet do |tweet| puts tweet.to_yaml end end |