Permalink
Browse files

Add AccessDeniedError to be used when LinkedIn returns 403 status code

  • Loading branch information...
1 parent 83fd81d commit c884a4d484228222d6ba60031ec927d39752ab46 Oliver Martell committed Jan 24, 2012
Showing with 11 additions and 1 deletion.
  1. +1 −0 lib/linked_in/errors.rb
  2. +4 −1 lib/linked_in/helpers/request.rb
  3. +6 −0 spec/cases/api_spec.rb
View
1 lib/linked_in/errors.rb
@@ -10,6 +10,7 @@ def initialize(data)
class UnauthorizedError < LinkedInError; end
class GeneralError < LinkedInError; end
+ class AccessDeniedError < LinkedInError; end
class UnavailableError < StandardError; end
class InformLinkedInError < StandardError; end
View
5 lib/linked_in/helpers/request.rb
@@ -44,9 +44,12 @@ def raise_errors(response)
when 401
data = Mash.from_json(response.body)
raise LinkedIn::Errors::UnauthorizedError.new(data), "(#{data.status}): #{data.message}"
- when 400, 403
+ when 400
data = Mash.from_json(response.body)
raise LinkedIn::Errors::GeneralError.new(data), "(#{data.status}): #{data.message}"
+ when 403
+ data = Mash.from_json(response.body)
+ raise LinkedIn::Errors::AccessDeniedError.new(data), "(#{data.status}): #{data.message}"
when 404
raise LinkedIn::Errors::NotFoundError, "(#{response.code}): #{response.message}"
when 500
View
6 spec/cases/api_spec.rb
@@ -83,4 +83,10 @@
end
end
+ context "Errors" do
+ it "should raise AccessDeniedError when LinkedIn returns 403 status code" do
+ stub_request(:get, "https://api.linkedin.com/v1/people-search?first-name=Javan").to_return(:body => "{}", :status => 403)
+ expect{ client.search(:first_name => "Javan") }.to raise_error(LinkedIn::Errors::AccessDeniedError)
+ end
+ end
end

0 comments on commit c884a4d

Please sign in to comment.