Permalink
Browse files

Merge branch 'player-not-found' of git://github.com/dewski/swish into…

… dewski-player-not-found
  • Loading branch information...
2 parents a1d0299 + 7728148 commit 2862fdc71de35c36b00e4c8174eb9044c89205fc @jeremyw committed Jul 27, 2013
Showing with 26 additions and 6 deletions.
  1. +16 −6 lib/dribbble/player.rb
  2. +4 −0 lib/swish.rb
  3. +6 −0 test/player_test.rb
View
@@ -1,30 +1,40 @@
module Dribbble
class Player < Base
+ def self.fetch(url, options = {})
+ user = get(url, options)
+
+ if user.response.is_a?(Net::HTTPNotFound)
+ raise PlayerNotFound
+ else
+ user
+ end
+ end
+
def self.find(id)
- new(get("/players/#{id}"))
+ new(fetch("/players/#{id}"))
end
# Fetches this player's shots.
# Options: :page, :per_page
def shots(options={})
- paginated_list(self.class.get("/players/#{@id}/shots", :query => options))
+ paginated_list(self.class.fetch("/players/#{@id}/shots", :query => options))
end
# Fetches shots by players that this player follows.
def shots_following(options={})
- paginated_list(self.class.get("/players/#{@id}/shots/following", :query => options))
+ paginated_list(self.class.fetch("/players/#{@id}/shots/following", :query => options))
end
def draftees(options={})
- paginated_list(self.class.get("/players/#{@id}/draftees", :query => options))
+ paginated_list(self.class.fetch("/players/#{@id}/draftees", :query => options))
end
def followers(options={})
- paginated_list(self.class.get("/players/#{@id}/followers", :query => options))
+ paginated_list(self.class.fetch("/players/#{@id}/followers", :query => options))
end
def following(options={})
- paginated_list(self.class.get("/players/#{@id}/following", :query => options))
+ paginated_list(self.class.fetch("/players/#{@id}/following", :query => options))
end
end
end
View
@@ -4,3 +4,7 @@
require 'dribbble/comment'
require 'dribbble/shot'
require 'dribbble/player'
+
+module Dribbble
+ class PlayerNotFound < Exception; end
+end
View
@@ -23,6 +23,12 @@ def test_find
end
end
+ def test_finding_invalid_user
+ assert_raises(Dribbble::PlayerNotFound) do
+ Dribbble::Player.find(999999)
+ end
+ end
+
def test_shots
player = Dribbble::Player.find(1)
shots = player.shots

0 comments on commit 2862fdc

Please sign in to comment.