yfantasy

package module
v0.1.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 13, 2022 License: Apache-2.0 Imports: 5 Imported by: 3

README

Yahoo Fantasy API Client for Go

Go Reference License Go Report Card

Installation

go get github.com/famendola1/yfantasy

Yahoo Endpoints

The Yahoo offical documentation for their Fantasy Sports API is not comprehensive and incomplete, despite being the offical. For a more complete overview of the supported endpoints, see the README.

Usage

There are two ways to interact with the Yahoo Fantasy API through this Go client:

  • Using high-level functions in api.go
  • Using the query builders in query/
Before You Start

Both of these usages require the use of a *http.Client that is configured for the Yahoo Fantasy API endpoint. You can use the github.com/famendola1/yauth package to configure a *http.Client to use.

High Level Functions

The high level functions in api.go provide additional functionality on top of the query builders. These functions can be accessed through the YFantasy struct. A valid YFantasy struct must be initialized with yfantasy.New prior to using these functions.

Contributions to set the high level functions provided through this client are welcome 🙂.

Query Builders

The query buiilders were designed to be able to easily generate queries for all the Yahoo Fantasy API endpoints. The builders expose functions that add pieces and parameters to the query. They also expose the following functions:

  • ToString: Builds the string for the query that the builder represents.
  • Get: Sends a GET request to the Yahoo Fantasy API for the endpoint that the query represents. A successful query will return a FantasyContent struct.

WARNING: The query builders do not validate that the queries they build are valid Yahoo endpoints.

Examples
// Get all the teams in a league.
Leagues().Key("nba.l.12345").Teams().Get(client)

// Search for a player and return their stats for the past week.
Leagues().Key("nba.l.12345").Players().Search("Donovan Mitchell").Stats().LastWeek().Get(client)

// Get all the leagues a user is in.
Users().Leagues().Get(client)

// Get the rosters for all teams in a league.
League().Key("nba.l.12345").Teams().Roster().Get(client)

// Get all the add and drop transactions in a league
League().Key("nba.l.12345").Transactions().Types([]string{"add", "drop"}).Get(client)

Projects using this client

A fantasy sports Discord bot is being developed with this client: https://github.com/famendola1/fantasy-discord-bot.

Documentation

Index

Constants

View Source
const (
	StatsTypeUnknown = iota
	StatsTypeSeason
	StatsTypeAverageSeason
	StatsTypeDate
	StatsTypeLastWeek
	StatsTypeLastWeekAverage
	StatsTypeLastMonth
	StatsTypeLastMonthAverage
)

Enum of types when requesting for stats.

Variables

This section is empty.

Functions

func MakeLeagueKey added in v0.1.0

func MakeLeagueKey(gameKey string, leagueID int) string

MakeLeagueKey creates a league key from the gameKey and leagueID.

Types

type YFantasy

type YFantasy struct {
	// contains filtered or unexported fields
}

YFantasy is the client for the Yahoo Fantasy API.

func New

func New(client *http.Client) *YFantasy

New returns a new YFantasy object.

func (*YFantasy) CurrentScoreboard added in v0.1.0

func (yf *YFantasy) CurrentScoreboard(leagueKey string) (*schema.Scoreboard, error)

CurrentScoreboard queries the Yahoo Fantasy API for a league's current scoreboard.

func (*YFantasy) League added in v0.0.27

func (yf *YFantasy) League(leagueKey string) (*schema.League, error)

League queries the Yahoo Fantasy API for a League.

func (*YFantasy) Player added in v0.1.2

func (yf *YFantasy) Player(leagueKey, name string) (*schema.Player, error)

Player searches the given league for a player with the provided player name. If the player is not found, an error is returned. name should contain at least 3 letters.

func (*YFantasy) PlayerAdvancedStats added in v0.1.2

func (yf *YFantasy) PlayerAdvancedStats(leagueKey, name string) (*schema.Player, error)

PlayerAdvancedStats searches the given league for a player with the provided player name and returns their advanced stats. If the player is not found, an error is returned. name should contain at least 3 letters.

func (*YFantasy) PlayerOwnership added in v0.1.6

func (yf *YFantasy) PlayerOwnership(leagueKey, name string) (*schema.Player, error)

PlayerOwnership searches the league for a player with the provided named and returns their ownership status.

func (*YFantasy) PlayerStats added in v0.1.2

func (yf *YFantasy) PlayerStats(leagueKey, name string, statsType int) (*schema.Player, error)

PlayerStats searches the given league for a player with the provided player name. and returns their average stats for the current season. If the player is not found, an error is returned. name should contain at least 3 letters.

func (*YFantasy) Rosters added in v0.1.0

func (yf *YFantasy) Rosters(leagueKey string) (*schema.Teams, error)

Rosters queries the Yahoo Fantasy API for all the team rosters in a league.

func (*YFantasy) Scoreboard added in v0.1.0

func (yf *YFantasy) Scoreboard(leagueKey string, week int) (*schema.Scoreboard, error)

Scoreboard queries the Yahoo Fantasy API for the scoreboard of a given week.

func (*YFantasy) SearchPlayers added in v0.1.2

func (yf *YFantasy) SearchPlayers(leagueKey, name string) ([]*schema.Player, error)

SearchPlayers searches the given league for a players with the provided player name. name should contain at least 3 letters.

func (*YFantasy) Standings added in v0.1.0

func (yf *YFantasy) Standings(leagueKey string) (*schema.Standings, error)

Standings queries the Yahoo Fantasy API for a leagues Standings.

func (*YFantasy) Team added in v0.0.27

func (yf *YFantasy) Team(leagueKey, teamName string) (*schema.Team, error)

Team searches the given league for a team with the provided team name. If the team is not found an error is returned.

func (*YFantasy) TeamRoster added in v0.1.2

func (yf *YFantasy) TeamRoster(leagueKey, teamName string) (*schema.Team, error)

TeamRoster searches the given league for a team with the provided team name and return's its roster. If the team is not found an error is returned.

func (*YFantasy) TeamStats added in v0.1.2

func (yf *YFantasy) TeamStats(leagueKey, teamName string, statsType int) (*schema.Team, error)

TeamStats searches the given league for a team with the provided team name and return's its stats. If the team is not found an error is returned.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL