Skip to content

Commit

Permalink
updated with leave and follow methods for twitter base and for the CL…
Browse files Browse the repository at this point in the history
…I. also updated the manifest.

git-svn-id: http://svn.addictedtonew.com/public/gems/twitter@164 fe7eae16-9a24-0410-a59d-9e59979e88be
  • Loading branch information
jnunemaker committed Jan 17, 2008
1 parent 9a53d29 commit 4878689
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
0.2.2 - added leave and follow which are new twitter api methods for turning notifications on and off
0.2.0 - Aug 4, 2007
* added sent_messages
* alias direct_messages to received_messages
Expand Down
14 changes: 9 additions & 5 deletions Manifest.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
README.txt
CHANGELOG
MIT-LICENSE
Manifest.txt
README.txt
Rakefile
setup.rb
bin/twitter
examples/twitter.rb
lib/twitter.rb
lib/twitter/base.rb
lib/twitter/command.rb
Expand All @@ -10,10 +13,11 @@ lib/twitter/easy_class_maker.rb
lib/twitter/status.rb
lib/twitter/user.rb
lib/twitter/version.rb
examples/twitter.rb
bin/twitter
setup.rb
test/test_helper.rb
test/unit/base_test.rb
test/unit/direct_message_test.rb
test/unit/status_test.rb
test/unit/user_test.rb
test/unit/user_test.rb
website/css/common.css
website/index.html
8 changes: 8 additions & 0 deletions lib/twitter/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ def destroy_friendship(id_or_screenname)
users(request("friendships/destroy/#{id_or_screenname}.xml", :auth => true)).first
end

def follow(id_or_screenname)
users(request("notifications/follow/#{id_or_screenname}.xml", :auth => true)).first
end

def leave(id_or_screenname)
users(request("notifications/leave/#{id_or_screenname}.xml", :auth => true)).first
end

# Updates your twitter with whatever status string is passed in
def post(status)
url = URI.parse("http://#{@@api_url}/statuses/update.xml")
Expand Down
42 changes: 41 additions & 1 deletion lib/twitter/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# It is only used and included in the bin/twitter file.
module Twitter
class Command
@@commands = [:post, :timeline, :friends, :friend, :followers, :follower, :featured, :important]
@@commands = [:post, :timeline, :friends, :friend, :followers, :follower, :featured, :important, :follow, :leave]

@@template = <<EOF
# .twitter
Expand Down Expand Up @@ -162,6 +162,46 @@ def important
end
end

def follow
config = create_or_find_config

if ARGV.size == 0
puts %(\n You forgot to enter a screen name or id to follow.\n\n Usage: twitter follow jnunemaker\n)
exit(0)
end

screen_name = ARGV.shift

puts
found = false
begin
Twitter::Base.new(config['email'], config['password']).follow(screen_name)
puts "You are now following notifications for #{screen_name}."
rescue
puts "FAIL: Somethin went wrong. Sorry."
end
end

def leave
config = create_or_find_config

if ARGV.size == 0
puts %(\n You forgot to enter a screen name or id to leave.\n\n Usage: twitter leave jnunemaker\n)
exit(0)
end

screen_name = ARGV.shift

puts
found = false
begin
Twitter::Base.new(config['email'], config['password']).leave(screen_name)
puts "You are no longer following notifications for #{screen_name}."
rescue
puts "FAIL: Somethin went wrong. Sorry."
end
end

private
# Checks for the config, creates it if not found
def create_or_find_config
Expand Down
2 changes: 1 addition & 1 deletion lib/twitter/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Twitter #:nodoc:
module VERSION #:nodoc:
MAJOR = 0
MINOR = 2
TINY = 1
TINY = 2

STRING = [MAJOR, MINOR, TINY].join('.')
end
Expand Down
10 changes: 10 additions & 0 deletions test/unit/base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ def setup
puts "Destroying Friendship with Snitch Test", @t.destroy_friendship('snitch_test'), "*"*50
puts "Creating Friendship with Snitch Test", @t.create_friendship('snitch_test'), "*"*50
end

test 'should be able to follow a user' do
puts "Following a user", @t.follow('jnunemaker'), "*"*50
end

test 'should be able to leave a user' do
puts "Leaving a user", @t.leave('jnunemaker'), "*"*50
end


#
# test 'should be able to destroy a status' do
# # this has to be checked individually, create a status, put the id in and make sure it was deleted
Expand Down

0 comments on commit 4878689

Please sign in to comment.