Documentation
¶
Overview ¶
Package goff provides a basic Yahoo Fantasy Sports API client.
This package is designed to facilitate communication with the Yahoo Fantasy Sports API. The steps required to get a new client up and running are as follows:
- Obtain an API key for your application. See https://developer.apps.yahoo.com/dashboard/createKey.html
- Call goff.GetConsumer(clientID, clientSecret) using your client's information.
- Use oauth.Consumer to obtain an oauth.AccessToken. See https://godoc.org/github.com/mrjones/oauth
- Call goff.NewOAuthClient(consumer, accessToken) with the consumer and access token.
- Use the returned client to make direct API requests with GetFantasyContent(url) or through one of the convenience methods. See http://developer.yahoo.com/fantasysports/guide/ for the type requests that can be made.
The goff client is currently in early stage development and the API is subject to change at any moment.
Index ¶
- Constants
- Variables
- func GetConsumer(clientID string, clientSecret string) *oauth.Consumer
- type Cache
- type Client
- func (c *Client) GetAllTeamStats(leagueKey string, week int) ([]Team, error)
- func (c *Client) GetAllTeams(leagueKey string) ([]Team, error)
- func (c *Client) GetFantasyContent(url string) (*FantasyContent, error)
- func (c *Client) GetLeagueMetadata(leagueKey string) (*League, error)
- func (c *Client) GetLeagueStandings(leagueKey string) (*League, error)
- func (c *Client) GetPlayersStats(leagueKey string, week int, players []Player) ([]Player, error)
- func (c *Client) GetTeam(teamKey string) (*Team, error)
- func (c *Client) GetTeamRoster(teamKey string, week int) ([]Player, error)
- func (c *Client) GetUserLeagues(year string) ([]League, error)
- func (c *Client) RequestCount() int
- type ContentProvider
- type FantasyContent
- type Game
- type LRUCache
- type LRUCacheValue
- type League
- type Manager
- type Matchup
- type Name
- type OAuthConsumer
- type Player
- type Points
- type Record
- type Roster
- type SelectedPosition
- type Team
- type TeamLogo
- type TeamStandings
- type User
Constants ¶
const ( // NflGameKey represents the current year's Yahoo fantasy football game NflGameKey = "nfl" // YahooBaseURL is the base URL for all calls to Yahoo's fantasy sports API YahooBaseURL = "http://fantasysports.yahooapis.com/fantasy/v2" // YahooRequestTokenURL is used to create OAuth request tokens YahooRequestTokenURL = "https://api.login.yahoo.com/oauth/v2/get_request_token" // YahooAuthTokenURL is used to create OAuth authorization tokens YahooAuthTokenURL = "https://api.login.yahoo.com/oauth/v2/request_auth" // YahooGetTokenURL is used to get the OAuth access token used when making // calls to the fantasy sports API. YahooGetTokenURL = "https://api.login.yahoo.com/oauth/v2/get_token" )
Variables ¶
var YearKeys = map[string]string{ "nfl": NflGameKey, "2014": "331", "2013": "314", "2012": "273", "2011": "257", "2010": "242", "2009": "222", "2008": "199", "2007": "175", "2006": "153", "2005": "124", "2004": "101", "2003": "79", "2002": "49", "2001": "57", }
YearKeys is map of a string year to the string Yahoo uses to identify the fantasy football game for that year.
Functions ¶
Types ¶
type Cache ¶ added in v0.2.0
type Cache interface { // Sets the content retrieved for the URL at the given time Set(url string, time time.Time, content *FantasyContent) // Gets the content for the URL given a time for which the content should // be valid Get(url string, time time.Time) (content *FantasyContent, ok bool) }
Cache sets and retrieves fantasy content for request URLs based on the time for which the content was valid
type Client ¶
type Client struct { // Provides fantasy content for this application. Provider ContentProvider }
Client is an application authorized to use the Yahoo fantasy sports API.
func NewCachedOAuthClient ¶ added in v0.2.0
func NewCachedOAuthClient( cache Cache, consumer OAuthConsumer, accessToken *oauth.AccessToken) *Client
NewCachedOAuthClient creates a new OAuth client that checks and updates the given Cache when retrieving fantasy content.
See NewLRUCache
func NewOAuthClient ¶
func NewOAuthClient(consumer OAuthConsumer, accessToken *oauth.AccessToken) *Client
NewOAuthClient creates a Client that uses oauth authentication to communicate with the Yahoo fantasy sports API. The consumer can be created with `GetConsumer` and then used to obtain the access token passed in here.
func (*Client) GetAllTeamStats ¶
GetAllTeamStats gets teams stats for a given week.
func (*Client) GetAllTeams ¶
GetAllTeams returns all teams playing in the given league.
func (*Client) GetFantasyContent ¶
func (c *Client) GetFantasyContent(url string) (*FantasyContent, error)
GetFantasyContent directly access Yahoo fantasy resources.
See http://developer.yahoo.com/fantasysports/guide/ for more information
func (*Client) GetLeagueMetadata ¶
GetLeagueMetadata returns the metadata associated with the given league.
func (*Client) GetLeagueStandings ¶ added in v0.3.0
GetLeagueStandings gets a league containing the current standings.
func (*Client) GetPlayersStats ¶
GetPlayersStats returns a list of Players containing their stats for the given week in the given year.
func (*Client) GetTeamRoster ¶
GetTeamRoster returns a team's roster for the given week.
func (*Client) GetUserLeagues ¶
GetUserLeagues returns a list of the current user's leagues for the given year.
func (*Client) RequestCount ¶
RequestCount returns the amount of requests made to the Yahoo API on behalf of the application represented by this Client.
type ContentProvider ¶
type ContentProvider interface { Get(url string) (content *FantasyContent, err error) // The amount of requests made to the Yahoo API on behalf of the application // represented by this Client. RequestCount() int }
ContentProvider returns the data from an API request.
type FantasyContent ¶
type FantasyContent struct { XMLName xml.Name `xml:"fantasy_content"` League League `xml:"league"` Team Team `xml:"team"` Users []User `xml:"users>user"` }
FantasyContent is the root level response containing the data from a request to the fantasy sports API.
type Game ¶
type Game struct {
Leagues []League `xml:"leagues>league"`
}
Game represents a single year in the Yahoo fantasy football ecosystem. It consists of zero or more leagues.
type LRUCache ¶ added in v0.3.0
type LRUCache struct { ClientID string Duration time.Duration DurationSeconds int64 Cache *lru.LRUCache }
LRUCache implements Cache utilizing a LRU cache and unique keys to cache content for up to a maximum duration.
func NewLRUCache ¶ added in v0.2.0
NewLRUCache creates a new Cache that caches content for the given client for up to the maximum duration.
See NewCachedOAuthClient
func (*LRUCache) Set ¶ added in v0.3.0
func (l *LRUCache) Set(url string, time time.Time, content *FantasyContent)
Set specifies that the given content was retrieved for the given URL at the given time. The content for that URL will be available by LRUCache.Get from the given 'time' up to 'time + l.Duration'
type LRUCacheValue ¶ added in v0.3.0
type LRUCacheValue struct {
// contains filtered or unexported fields
}
LRUCacheValue implements lru.Value to be able to store fantasy content in a LRUCache
func (*LRUCacheValue) Size ¶ added in v0.3.0
func (v *LRUCacheValue) Size() int
Size always returns '1'. All LRU cache values have the same size, meaning the backing lru.LRUCache will prune strictly based on number of cached content and not the total size in memory.
type League ¶
type League struct { LeagueKey string `xml:"league_key"` LeagueID uint64 `xml:"league_id"` Name string `xml:"name"` Players []Player `xml:"players>player"` Teams []Team `xml:"teams>team"` DraftStatus string `xml:"draft_status"` CurrentWeek int `xml:"current_week"` StartWeek int `xml:"start_week"` EndWeek int `xml:"end_week"` IsFinished bool `xml:"is_finished"` Standings []Team `xml:"standings>teams>team"` }
A League is a uniquely identifiable group of players and teams. The scoring system, roster details, and other metadata can differ between leagues.
type Manager ¶
type Manager struct { ManagerID uint64 `xml:"manager_id"` Nickname string `xml:"nickname"` GUID string `xml:"guid"` IsCurrentLogin bool `xml:"is_current_login"` }
A Manager is a user in change of a given team.
type OAuthConsumer ¶
type OAuthConsumer interface {
Get(url string, data map[string]string, token *oauth.AccessToken) (*http.Response, error)
}
OAuthConsumer returns data from an oauth provider
type Player ¶
type Player struct { PlayerKey string `xml:"player_key"` PlayerID uint64 `xml:"player_id"` Name Name `xml:"name"` DisplayPosition string `xml:"display_position"` ElligiblePositions []string `xml:"elligible_positions>position"` SelectedPosition SelectedPosition `xml:"selected_position"` PlayerPoints Points `xml:"player_points"` }
A Player is a single player for the given sport.
type Points ¶
type Points struct { CoverageType string `xml:"coverage_type"` Season string `xml:"season"` Week int `xml:"week"` Total float64 `xml:"total"` }
Points represents scoring statistics for a time period specified by CoverageType.
type Roster ¶
type Roster struct { CoverageType string `xml:"coverage_type"` Players []Player `xml:"players>player"` Week int `xml:"week"` }
A Roster is the set of players belonging to one team for a given week.
type SelectedPosition ¶
type SelectedPosition struct { CoverageType string `xml:"coverage_type"` Week int `xml:"week"` Position string `xml:"position"` }
SelectedPosition is the position chosen for a Player for a given week.
type Team ¶
type Team struct { TeamKey string `xml:"team_key"` TeamID uint64 `xml:"team_id"` Name string `xml:"name"` URL string `xml:"url"` TeamLogos []TeamLogo `xml:"team_logos>team_logo"` IsOwnedByCurrentLogin bool `xml:"is_owned_by_current_login"` WavierPriority int `xml:"waiver_priority"` NumberOfMoves int `xml:"number_of_moves"` NumberOfTrades int `xml:"number_of_trades"` Managers []Manager `xml:"managers>manager"` Matchups []Matchup `xml:"matchups>matchup"` Roster Roster `xml:"roster"` TeamPoints Points `xml:"team_points"` TeamProjectedPoints Points `xml:"team_projected_points"` TeamStandings TeamStandings `xml:"team_standings"` Players []Player `xml:"players>player"` }
A Team is a participant in exactly one league.