Permalink
Browse files

- more specific error handling for 403 situations

- adds exceptions CantFindUsers, AlreadyFollowing, and CantFollowUser
- one rspect test for creating a frienship
- need to work out a means to spec the exception throwing, gonna
 test by hand for now

Signed-off-by: John Nunemaker <nunemaker@gmail.com>
  • Loading branch information...
billymeltdown authored and jnunemaker committed Dec 14, 2008
1 parent a85cb35 commit 2b85bed874902d184e5d53c0a0bd249fd1ed3b8b
Showing with 36 additions and 0 deletions.
  1. +3 −0 lib/twitter.rb
  2. +4 −0 lib/twitter/base.rb
  3. +12 −0 spec/base_spec.rb
  4. +5 −0 spec/fixtures/friendship_already_exists.xml
  5. +12 −0 spec/fixtures/friendship_created.xml
View
@@ -24,6 +24,9 @@ class CantConnect < StandardError; end
class BadResponse < StandardError; end
class UnknownTimeline < ArgumentError; end
class RateExceeded < StandardError; end
+ class CantFindUsers < ArgumentError; end
+ class AlreadyFollowing < StandardError; end
+ class CantFollowUser < StandardError; end
SourceName = 'twittergem'
end
View
@@ -230,6 +230,10 @@ def request(path, options={})
raise Unavailable, response.message
elsif response.code == '401'
raise CantConnect, 'Authentication failed. Check your username and password'
+ elsif response.code == '403'
+ raise CantFindUsers if (response/:hash/:error).text =~ /Could not find both specified users/
+ raise AlreadyFollowing if (response/:hash/:error).text =~ /already on your list/
+ raise CantFollowUser, "Response code #{response.code}: #{response.message} #{(response/:hash/:error).text}"
else
raise CantConnect, "Twitter is returning a #{response.code}: #{response.message}"
end
View
@@ -69,6 +69,18 @@
timeline.size.should == 29
timeline.first.name.should == 'Blaine Cook'
end
+
+ it "should be able to create a friendship" do
+ data = open(File.dirname(__FILE__) + '/fixtures/friendship_created.xml').read
+ @base.should_receive(:request).and_return(Hpricot::XML(data))
+ user = @base.create_friendship('jnunemaker')
+ end
+
+ it "should bomb if friendship already exists" #do
+ # data = open(File.dirname(__FILE__) + '/fixtures/friendship_already_exists.xml').read
+ # @base.should_receive(:request).and_return(Hpricot::XML(data))
+ # lambda { @base.create_friendship('billymeltdown') }.should raise_error(Twitter::AlreadyFollowing)
+ #end
end
it "should be able to get single status" do
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<hash>
+ <request>/friendships/create/billymeltdown.xml</request>
+ <error>Could not follow user: billymeltdown is already on your list.</error>
+</hash>
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<user>
+ <id>4243</id>
+ <name>John Nunemaker</name>
+ <screen_name>jnunemaker</screen_name>
+ <location>Indiana</location>
+ <description>Loves his wife, ruby, notre dame football and iu basketball</description>
+ <profile_image_url>http://s3.amazonaws.com/twitter_production/profile_images/52619256/ruby_enterprise_shirt_normal.jpg</profile_image_url>
+ <url>http://addictedtonew.com</url>
+ <protected>false</protected>
+ <followers_count>363</followers_count>
+</user>

0 comments on commit 2b85bed

Please sign in to comment.