Permalink
Browse files

Added new CLI method open which opens a profile page for a user. Adde…

…d --force options to ignore since id in replies and timelines. Refactored output of tweets.
  • Loading branch information...
1 parent b16bc27 commit 84e77a1d515f762d7a24f697786f5959d4f1cc2e @jnunemaker jnunemaker committed Jul 23, 2008
Showing with 62 additions and 24 deletions.
  1. +5 −0 History.txt
  2. +3 −0 TODO.txt
  3. +35 −23 lib/twitter/cli.rb
  4. +18 −0 lib/twitter/cli/helpers.rb
  5. +1 −1 lib/twitter/version.rb
View
@@ -1,3 +1,8 @@
+0.3.1 - July 23, 2008
+ * added open to CLI twitter open jnunemaker would open default browser to http://twitter.com/jnunemaker
+ * added -f to timeline and replies which ignores the since_id and shows all results
+ * added clear_config to remove all cached since id's and such
+
0.3.0 - July 22, 2008
* complete rewrite of CLI. Now supports multiple accounts and changing between them.
* added source, truncated, in_reply_to_status_id, in_reply_to_user_id, and favorited to Twitter::Status
View
@@ -0,0 +1,3 @@
+* format the tweets in a more readable fashion (limit words per line so more scannable)
+* add timeout so it doesn't hang forever like it does now if twitter is down
+* add progress indicator for timeline and replies as posting has for more visual indication that work is happening
View
@@ -253,45 +253,57 @@ def run
description 'the timeline you wish to see (friends, public, me)'
default 'friends'
}
+ option('force', 'f') {
+ description "Ignore since_id and show first page of results even if there aren't new ones"
+ }
def run
do_work do
timeline = params['timeline'].value == 'me' ? 'user' : params['timeline'].value
options, since_id = {}, Configuration["#{timeline}_last_id"]
- options[:since_id] = since_id unless since_id.blank?
- statuses = base.timeline(timeline.to_sym, options)
- username_length = statuses.collect { |s| s.user.screen_name }.max { |a,b| a.length <=> b.length }.length rescue 0
- if statuses.size > 0
- statuses.each do |s|
- Tweet.create_from_tweet(current_account, s) if timeline != :public
- say "#{CGI::unescapeHTML(s.user.screen_name.ljust(username_length+1))}: #{CGI::unescapeHTML(s.text)} on #{Time.parse(s.created_at).strftime('%b %d at %l:%M%P')}"
- end
- Configuration["#{timeline}_last_id"] = statuses.first.id
- else
- say 'Nothing new since your last check'
- end
+ options[:since_id] = since_id if !since_id.blank? && !params['force'].given?
+ cache = [:friends, :user].include?(timeline)
+ collection = base.timeline(timeline.to_sym, options)
+ output_tweets(collection, {:cache => cache, :since_prefix => timeline})
end
end
end
mode 'replies' do
description 'Allows you to view all @replies at you'
+ option('force', 'f') {
+ description "Ignore since_id and show first page of replies even if there aren't new ones"
+ }
def run
do_work do
options, since_id = {}, Configuration["replies_since_id"]
- options[:since_id] = since_id if !since_id.blank?
- replies = base.replies(options)
- username_length = replies.collect { |s| s.user.screen_name }.max { |a,b| a.length <=> b.length }.length rescue 0
- if replies.size > 0
- replies.each do |s|
- say "#{CGI::unescapeHTML(s.user.screen_name.ljust(username_length+1))}: #{CGI::unescapeHTML(s.text)} on #{Time.parse(s.created_at).strftime('%b %d at %l:%M%P')}"
- end
- Configuration["replies_since_id"] = replies.first.id
- else
- say 'No new replies since your last check'
- end
+ options[:since_id] = since_id if !since_id.blank? && !params['force'].given?
+ collection = base.replies(options)
+ output_tweets(collection, {:since_prefix => 'replies'})
+ end
+ end
+ end
+
+ mode 'clear_config' do
+ def run
+ do_work do
+ count = Configuration.count
+ Configuration.destroy_all
+ say("#{count} configuration entries cleared.")
end
end
end
+
+ mode 'open' do
+ description 'Opens the given twitter user in a browser window'
+ argument('username') {
+ required
+ description "username or id of twitterrer who's page you would like to see"
+ }
+
+ def run
+ `open http://twitter.com/#{params['username'].value}`
+ end
+ end
}
View
@@ -1,6 +1,24 @@
module Twitter
module CLI
module Helpers
+ def output_tweets(collection, options={})
+ options.reverse_merge!({
+ :cache => false,
+ :since_prefix => '',
+ :empty_msg => 'Nothing new since your last check.'
+ })
+ if collection.size > 0
+ username_length = collect.collect { |s| s.user.screen_name }.max { |a,b| a.length <=> b.length }.length rescue 0
+ collection.each do |s|
+ Tweet.create_from_tweet(current_account, s) if options[:cache]
+ say "#{CGI::unescapeHTML(s.user.screen_name.ljust(username_length+1))}: #{CGI::unescapeHTML(s.text)} -- on #{Time.parse(s.created_at).strftime('%b %d at %l:%M%P')}"
+ end
+ Configuration["#{options[:since_prefix]}_since_id"] = collection.first.id
+ else
+ say(options[:empty_msg])
+ end
+ end
+
def base(username=current_account.username, password=current_account.password)
@base ||= Twitter::Base.new(username, password)
end
View
@@ -2,7 +2,7 @@ module Twitter #:nodoc:
module VERSION #:nodoc:
MAJOR = 0
MINOR = 3
- TINY = 0
+ TINY = 1
STRING = [MAJOR, MINOR, TINY].join('.')
end

0 comments on commit 84e77a1

Please sign in to comment.