Permalink
Browse files

added #base and #current_account helpers. added #follow and #leave.

  • Loading branch information...
1 parent 215b2ca commit ad2da1676a38e3fd1b2c0d8ec581d9a220ec5889 @jnunemaker jnunemaker committed Jul 22, 2008
Showing with 56 additions and 23 deletions.
  1. +45 −22 lib/twitter/cli.rb
  2. +11 −1 lib/twitter/cli/helpers.rb
View
@@ -51,7 +51,7 @@ def run
end
do_work do
- Twitter::Base.new(account[:username], account[:password]).verify_credentials
+ base(account[:username], account[:password]).verify_credentials
account[:current] = Account.current.count > 0 ? false : true
Account.create(account)
say 'Account added.'
@@ -131,36 +131,59 @@ def run
rescue ActiveRecord::RecordNotFound
say "ERROR: Account could not be found. Try again. \n"
end
-
end
end
end
mode 'post' do
-
def run
do_work do
- account = Account.active
- if account
- post = if ARGV.size > 1
- ARGV.join " "
- else
- ARGV.shift
- end
-
- say "Sending twitter update"
- finished, status = false, nil
- progress_thread = Thread.new { until finished; print "."; $stdout.flush; sleep 0.5; end; }
- post_thread = Thread.new(binding()) do |b|
- status = Twitter::Base.new(account.username, account.password).post(post, :source => Twitter::SourceName)
- finished = true
- end
- post_thread.join
- progress_thread.join
- say "Got it! New twitter created at: #{status.created_at}\n"
+ post = if ARGV.size > 1
+ ARGV.join " "
else
- say 'You do not have a current account set.'
+ ARGV.shift
+ end
+
+ say "Sending twitter update"
+ finished, status = false, nil
+ progress_thread = Thread.new { until finished; print "."; $stdout.flush; sleep 0.5; end; }
+ post_thread = Thread.new(binding()) do |b|
+ status = base.post(post, :source => Twitter::SourceName)
+ finished = true
end
+ post_thread.join
+ progress_thread.join
+ say "Got it! New twitter created at: #{status.created_at}\n"
+ end
+ end
+ end
+
+ mode 'follow' do
+ argument('username') {
+ required
+ description 'username or id of twitterrer to follow'
+ }
+
+ def run
+ do_work do
+ username = params['username'].value
+ base.follow(username)
+ say "You are now following notifications from #{username}"
+ end
+ end
+ end
+
+ mode 'leave' do
+ argument('username') {
+ required
+ description 'username or id of twitterrer to leave'
+ }
+
+ def run
+ do_work do
+ username = params['username'].value
+ base.leave(username)
+ say "You are no longer following notifications from #{username}"
end
end
end
View
@@ -1,6 +1,16 @@
module Twitter
module CLI
- module Helpers
+ module Helpers
+ def base(username=current_account.username, password=current_account.password)
+ @base ||= Twitter::Base.new(username, password)
+ end
+
+ def current_account
+ @current_account ||= Account.active
+ exit('No current account.') if @current_account.blank?
+ @current_account
+ end
+
def do_work(&block)
connect
begin

0 comments on commit ad2da16

Please sign in to comment.