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
- #reply(twitter_id, status) ⇒ 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 8 9 10 11 |
# File 'lib/tweetline/cli.rb', line 3 def initialize(*) super Tweetline.configure_twitter Tweetline.configure_pipes Signal.trap("SIGINT") do exit! end end |
Instance Method Details
#cat(twitter_id = "") ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/tweetline/cli.rb', line 16 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
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/tweetline/cli.rb', line 28 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
40 41 42 43 44 45 46 47 |
# File 'lib/tweetline/cli.rb', line 40 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
50 51 52 53 54 |
# File 'lib/tweetline/cli.rb', line 50 def json Tweetline.each_tweet do |tweet| puts tweet.to_json end end |
#ls(screen_name = "") ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/tweetline/cli.rb', line 57 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 |
#reply(twitter_id, status) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/tweetline/cli.rb', line 66 def reply(twitter_id, status) status = "@#{Twitter.status(twitter_id).user.screen_name} #{status}" if status.length > 140 puts "" puts "This status is too long." puts "" puts " #{status[0..139]}" puts "" else Twitter.update(status, :in_reply_to_status_id => twitter_id) end end |
#retweet(twitter_id = "") ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/tweetline/cli.rb', line 80 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
93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/tweetline/cli.rb', line 93 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
106 107 108 109 110 |
# File 'lib/tweetline/cli.rb', line 106 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
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/tweetline/cli.rb', line 115 def tail previous_id = "1" begin if [:follow] if previous_id == "1" count = 1 else count = 100 end else count = [:number] end tweets = Twitter.home_timeline(:count => count, :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 [:follow] end while [:follow] end |
#unfollow(screen_name = "") ⇒ Object
139 140 141 142 143 144 145 146 147 148 |
# File 'lib/tweetline/cli.rb', line 139 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
151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/tweetline/cli.rb', line 151 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
164 165 166 167 168 |
# File 'lib/tweetline/cli.rb', line 164 def yaml Tweetline.each_tweet do |tweet| puts tweet.to_yaml end end |