Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Don't suppress `Twitter::Error::Forbidden` in #follow and #follow!

Closes #502.
  • Loading branch information...
commit b949c0400dabc6774419025e7b131d0a18447c3a 1 parent 6a47e71
@sferik authored
View
1  lib/twitter/error.rb
@@ -19,6 +19,7 @@ module Codes
OVER_CAPACITY = 130
INTERNAL_ERROR = 131
OAUTH_TIMESTAMP_OUT_OF_RANGE = 135
+ FOLLOW_ALREADY_REQUESTED = 160
FOLLOW_LIMIT_EXCEEDED = 161
PROTECTED_STATUS = 179
OVER_UPDATE_LIMIT = 185
View
8 lib/twitter/rest/api/friends_and_followers.rb
@@ -137,13 +137,7 @@ def follow(*args)
def follow!(*args)
arguments = Twitter::Arguments.new(args)
arguments.flatten.threaded_map do |user|
- begin
- object_from_response(Twitter::User, :post, '/1.1/friendships/create.json', merge_user(arguments.options, user))
- rescue Twitter::Error::Forbidden
- # This error will be raised if the user doesn't have permission to
- # follow list_member, for whatever reason.
- next
- end
+ object_from_response(Twitter::User, :post, '/1.1/friendships/create.json', merge_user(arguments.options, user))
end.compact
end
alias_method :create_friendship!, :follow!
View
1  spec/fixtures/forbidden.json
@@ -0,0 +1 @@
+{"errors":[{"code":160,"message":"You've already requested to follow %s."}]}
View
2  spec/helper.rb
@@ -8,7 +8,7 @@
SimpleCov.start do
add_filter '/spec/'
- minimum_coverage(99.07)
+ minimum_coverage(99.13)
end
require 'twitter'
View
8 spec/twitter/rest/api/friends_and_followers_spec.rb
@@ -352,6 +352,14 @@
expect(a_post('/1.1/friendships/create.json').with(:body => {:screen_name => 'sferik'})).to have_been_made
end
end
+ context 'with a forbidden error' do
+ before do
+ stub_post('/1.1/friendships/create.json').with(:body => {:screen_name => 'sferik'}).to_return(:status => 403, :body => fixture('forbidden.json'), :headers => {:content_type => 'application/json; charset=utf-8'})
+ end
+ it 'raises an exception' do
+ expect { @client.follow!('sferik') }.to raise_error(Twitter::Error::Forbidden)
+ end
+ end
describe '#unfollow' do
before do
Please sign in to comment.
Something went wrong with that request. Please try again.