Skip to content
This repository has been archived by the owner on Feb 9, 2019. It is now read-only.

Commit

Permalink
Merge branch 'player-not-found' of git://github.com/dewski/swish into…
Browse files Browse the repository at this point in the history
… dewski-player-not-found
  • Loading branch information
Jeremy Weiskotten committed Jul 27, 2013
2 parents a1d0299 + 7728148 commit 2862fdc
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
22 changes: 16 additions & 6 deletions lib/dribbble/player.rb
@@ -1,30 +1,40 @@
module Dribbble module Dribbble
class Player < Base 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) def self.find(id)
new(get("/players/#{id}")) new(fetch("/players/#{id}"))
end end


# Fetches this player's shots. # Fetches this player's shots.
# Options: :page, :per_page # Options: :page, :per_page
def shots(options={}) def shots(options={})
paginated_list(self.class.get("/players/#{@id}/shots", :query => options)) paginated_list(self.class.fetch("/players/#{@id}/shots", :query => options))
end end


# Fetches shots by players that this player follows. # Fetches shots by players that this player follows.
def shots_following(options={}) 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 end


def draftees(options={}) def draftees(options={})
paginated_list(self.class.get("/players/#{@id}/draftees", :query => options)) paginated_list(self.class.fetch("/players/#{@id}/draftees", :query => options))
end end


def followers(options={}) def followers(options={})
paginated_list(self.class.get("/players/#{@id}/followers", :query => options)) paginated_list(self.class.fetch("/players/#{@id}/followers", :query => options))
end end


def following(options={}) 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 end
end end
4 changes: 4 additions & 0 deletions lib/swish.rb
Expand Up @@ -4,3 +4,7 @@
require 'dribbble/comment' require 'dribbble/comment'
require 'dribbble/shot' require 'dribbble/shot'
require 'dribbble/player' require 'dribbble/player'

module Dribbble
class PlayerNotFound < Exception; end
end
6 changes: 6 additions & 0 deletions test/player_test.rb
Expand Up @@ -23,6 +23,12 @@ def test_find
end end
end end


def test_finding_invalid_user
assert_raises(Dribbble::PlayerNotFound) do
Dribbble::Player.find(999999)
end
end

def test_shots def test_shots
player = Dribbble::Player.find(1) player = Dribbble::Player.find(1)
shots = player.shots shots = player.shots
Expand Down

0 comments on commit 2862fdc

Please sign in to comment.