Packages

An Elixir wrapper for the Fantasy Football Nerd API (http://www.fantasyfootballnerd.com/fantasy-football-api)

Current section

Files

Jump to
ffnerd lib ffnerd player.ex
Raw

lib/ffnerd/player.ex

defmodule FFNerd.Player do
defstruct [:player_id, :star, :active, :jersey, :fname, :lname, :display_name, :team, :position, :height, :weight, :dob, :college, :twitter_id]
use ExConstructor
@moduledoc """
Provides functions to work with Fantasy Football Nerd's Players resources.
More info at: http://www.fantasyfootballnerd.com/fantasy-football-api#players
"""
@doc """
Return a list of all player records.
## Examples
FFNerd.Player.list client
"""
def list(client) do
{:Players, %FFNerd.URL{service: "players"}}
|> FFNerd.get(client)
|> Enum.map(&new/1)
end
@doc """
Return a list of player records by position code.
## Examples
FFNerd.Player.list "QB", client
"""
def list(position, client) do
{:Players, %FFNerd.URL{service: "players", path1: position}}
|> FFNerd.get(client)
|> Enum.map(&new/1)
end
@doc """
Return a single player record by player id or display name
## Examples
FFNerd.Player.find 2, client
FFNerd.Player.find "Russell Wilson", client
"""
def find(id, client) when is_integer(id) do
client |> list |> Enum.find(&(&1.player_id == "#{id}"))
end
def find(name, client) do
client |> list |> Enum.find(&(&1.display_name == name))
end
end