From d0afff06fcc0f78fce5343d11c6f5c921b13c5e3 Mon Sep 17 00:00:00 2001 From: Carl Kittelberger Date: Sat, 9 Jul 2016 20:59:24 +0200 Subject: [PATCH] Deprecate Soccerseason methods and structs in favor of the Competition model. Deprecated structs and methods will be removed before tagging v1 of the implementation. --- api_types.go | 20 ++++++++++++++++++ req_competition.go | 19 +++++++++++++++++ req_competition_fixtures.go | 36 +++++++++++++++++++++++++++++++++ req_competition_leaguetable.go | 27 +++++++++++++++++++++++++ req_competition_teams.go | 19 +++++++++++++++++ req_competitions.go | 27 +++++++++++++++++++++++++ req_soccerseason.go | 6 ++++++ req_soccerseason_fixtures.go | 10 +++++++++ req_soccerseason_leaguetable.go | 6 ++++++ req_soccerseason_teams.go | 6 ++++++ req_soccerseasons.go | 8 ++++++++ 11 files changed, 184 insertions(+) create mode 100644 req_competition.go create mode 100644 req_competition_fixtures.go create mode 100644 req_competition_leaguetable.go create mode 100644 req_competition_teams.go create mode 100644 req_competitions.go diff --git a/api_types.go b/api_types.go index 673f7e3..a0bbe98 100644 --- a/api_types.go +++ b/api_types.go @@ -23,9 +23,13 @@ const ( Venue_Away Venue = "away" ) +// DEPRECATED. +// // Contains the list of soccer seasons returned by the API. type SoccerSeasonList []SoccerSeason +// DEPRECATED. +// // Contains information about a soccer season. type SoccerSeason struct { Id uint64 @@ -39,6 +43,22 @@ type SoccerSeason struct { LastUpdated time.Time } +// Contains the list of competitions returned by the API. +type CompetitionList []Competitions + +// Contains information about a competition. +type Competition struct { + Id uint64 + Caption string + League string + Year string + CurrentMatchday uint16 + NumberOfMatchdays uint16 + NumberOfTeams uint16 + NumberOfGames uint16 + LastUpdated time.Time +} + // Contains the fixture and the head to head information delivered by the API // for a wanted fixture. type FixtureResponse struct { diff --git a/req_competition.go b/req_competition.go new file mode 100644 index 0000000..b4aa6ea --- /dev/null +++ b/req_competition.go @@ -0,0 +1,19 @@ +package footballdata + +type CompetitionRequest struct{ request } + +// Do executes the request. +func (r CompetitionRequest) Do() (s Competition, err error) { + d, _, err := r.doJson("GET") + if err != nil { + return + } + + err = d.Decode(&s) + return +} + +// Competition prepares a request to fetch the complete list of soccer seasons. +func (c *Client) Competition(id uint64) CompetitionRequest { + return CompetitionRequest{c.req("competitions/%d", id)} +} diff --git a/req_competition_fixtures.go b/req_competition_fixtures.go new file mode 100644 index 0000000..ac41957 --- /dev/null +++ b/req_competition_fixtures.go @@ -0,0 +1,36 @@ +package footballdata + +import ( + "fmt" + "time" +) + +type CompetitionFixturesRequest struct{ request } + +// Matchday modifies the request to specify a match day. +func (r CompetitionFixturesRequest) Matchday(matchday uint16) CompetitionFixturesRequest { + r.urlValues.Set("matchday", fmt.Sprintf("%d", matchday)) + return r +} + +// TimeFrame modifies the request to specify a specific time frame. +func (r CompetitionFixturesRequest) TimeFrame(timeframe time.Duration) CompetitionFixturesRequest { + r.urlValues.Set("timeFrame", durationToTimeFrame(timeframe)) + return r +} + +// Do executes the request. +func (r CompetitionFixturesRequest) Do() (s FixtureList, err error) { + d, _, err := r.doJson("GET") + if err != nil { + return + } + + err = d.Decode(&s) + return +} + +// FixturesOfCompetition prepares a request to fetch the fixtures of a soccer season. +func (c *Client) FixturesOfCompetition(soccerSeasonId uint64) CompetitionFixturesRequest { + return CompetitionFixturesRequest{c.req("competitions/%d/fixtures", soccerSeasonId)} +} diff --git a/req_competition_leaguetable.go b/req_competition_leaguetable.go new file mode 100644 index 0000000..db9f046 --- /dev/null +++ b/req_competition_leaguetable.go @@ -0,0 +1,27 @@ +package footballdata + +import "fmt" + +type CompetitionLeagueTableRequest struct{ request } + +// Matchday modifies the request to specify a match day. +func (r CompetitionLeagueTableRequest) Matchday(matchday uint16) CompetitionLeagueTableRequest { + r.urlValues.Set("matchday", fmt.Sprintf("%d", matchday)) + return r +} + +// Do executes the request. +func (r CompetitionLeagueTableRequest) Do() (s Competition, err error) { + d, _, err := r.doJson("GET") + if err != nil { + return + } + + err = d.Decode(&s) + return +} + +// LeagueTableOfCompetition prepares a new request to fetch the league table of a given soccer season. +func (c *Client) LeagueTableOfCompetition(soccerSeasonId uint64) CompetitionLeagueTableRequest { + return CompetitionLeagueTableRequest{c.req("competitions/%d/leagueTable", soccerSeasonId)} +} diff --git a/req_competition_teams.go b/req_competition_teams.go new file mode 100644 index 0000000..7e9a659 --- /dev/null +++ b/req_competition_teams.go @@ -0,0 +1,19 @@ +package footballdata + +type CompetitionTeamsRequest struct{ request } + +// Do executes the request. +func (r CompetitionTeamsRequest) Do() (s TeamList, err error) { + d, _, err := r.doJson("GET") + if err != nil { + return + } + + err = d.Decode(&s) + return +} + +// TeamsOfCompetition prepares a new request to fetch the league table of a given soccer season. +func (c *Client) TeamsOfCompetition(soccerSeasonId uint64) CompetitionTeamsRequest { + return CompetitionTeamsRequest{c.req("competitions/%d/leagueTable", soccerSeasonId)} +} diff --git a/req_competitions.go b/req_competitions.go new file mode 100644 index 0000000..c414f66 --- /dev/null +++ b/req_competitions.go @@ -0,0 +1,27 @@ +package footballdata + +import "fmt" + +type CompetitionsRequest struct{ request } + +// Season modifies the request to specify a season. +func (r CompetitionsRequest) Season(num uint32) CompetitionsRequest { + r.urlValues.Set("season", fmt.Sprintf("%d", num)) + return r +} + +// Do executes the request. +func (r CompetitionsRequest) Do() (s CompetitionList, err error) { + d, _, err := r.doJson("GET") + if err != nil { + return + } + + err = d.Decode(&s) + return +} + +// Competitions prepares a request to fetch the complete list of soccer seasons. +func (c *Client) Competitions() CompetitionsRequest { + return CompetitionsRequest{c.req("competitions")} +} diff --git a/req_soccerseason.go b/req_soccerseason.go index 1bfa417..5e14367 100644 --- a/req_soccerseason.go +++ b/req_soccerseason.go @@ -1,7 +1,11 @@ package footballdata +// DEPRECATED. +// type SoccerSeasonRequest struct{ request } +// DEPRECATED. +// // Do executes the request. func (r SoccerSeasonRequest) Do() (s SoccerSeason, err error) { d, _, err := r.doJson("GET") @@ -13,6 +17,8 @@ func (r SoccerSeasonRequest) Do() (s SoccerSeason, err error) { return } +// DEPRECATED. +// // SoccerSeason prepares a request to fetch the complete list of soccer seasons. func (c *Client) SoccerSeason(id uint64) SoccerSeasonRequest { return SoccerSeasonRequest{c.req("soccerseasons/%d", id)} diff --git a/req_soccerseason_fixtures.go b/req_soccerseason_fixtures.go index 7f95b47..58b5c90 100644 --- a/req_soccerseason_fixtures.go +++ b/req_soccerseason_fixtures.go @@ -5,20 +5,28 @@ import ( "time" ) +// DEPRECATED. +// type SoccerSeasonFixturesRequest struct{ request } +// DEPRECATED. +// // Matchday modifies the request to specify a match day. func (r SoccerSeasonFixturesRequest) Matchday(matchday uint16) SoccerSeasonFixturesRequest { r.urlValues.Set("matchday", fmt.Sprintf("%d", matchday)) return r } +// DEPRECATED. +// // TimeFrame modifies the request to specify a specific time frame. func (r SoccerSeasonFixturesRequest) TimeFrame(timeframe time.Duration) SoccerSeasonFixturesRequest { r.urlValues.Set("timeFrame", durationToTimeFrame(timeframe)) return r } +// DEPRECATED. +// // Do executes the request. func (r SoccerSeasonFixturesRequest) Do() (s FixtureList, err error) { d, _, err := r.doJson("GET") @@ -30,6 +38,8 @@ func (r SoccerSeasonFixturesRequest) Do() (s FixtureList, err error) { return } +// DEPRECATED. +// // FixturesOfSoccerSeason prepares a request to fetch the fixtures of a soccer season. func (c *Client) FixturesOfSoccerSeason(soccerSeasonId uint64) SoccerSeasonFixturesRequest { return SoccerSeasonFixturesRequest{c.req("soccerseasons/%d/fixtures", soccerSeasonId)} diff --git a/req_soccerseason_leaguetable.go b/req_soccerseason_leaguetable.go index 7fd6cbf..51c31e3 100644 --- a/req_soccerseason_leaguetable.go +++ b/req_soccerseason_leaguetable.go @@ -4,12 +4,16 @@ import "fmt" type SoccerSeasonLeagueTableRequest struct{ request } +// DEPRECATED. +// // Matchday modifies the request to specify a match day. func (r SoccerSeasonLeagueTableRequest) Matchday(matchday uint16) SoccerSeasonLeagueTableRequest { r.urlValues.Set("matchday", fmt.Sprintf("%d", matchday)) return r } +// DEPRECATED. +// // Do executes the request. func (r SoccerSeasonLeagueTableRequest) Do() (s SoccerSeason, err error) { d, _, err := r.doJson("GET") @@ -21,6 +25,8 @@ func (r SoccerSeasonLeagueTableRequest) Do() (s SoccerSeason, err error) { return } +// DEPRECATED. +// // LeagueTableOfSoccerSeason prepares a new request to fetch the league table of a given soccer season. func (c *Client) LeagueTableOfSoccerSeason(soccerSeasonId uint64) SoccerSeasonLeagueTableRequest { return SoccerSeasonLeagueTableRequest{c.req("soccerseasons/%d/leagueTable", soccerSeasonId)} diff --git a/req_soccerseason_teams.go b/req_soccerseason_teams.go index 1ec633c..480634a 100644 --- a/req_soccerseason_teams.go +++ b/req_soccerseason_teams.go @@ -1,7 +1,11 @@ package footballdata +// DEPRECATED. +// type SoccerSeasonTeamsRequest struct{ request } +// DEPRECATED. +// // Do executes the request. func (r SoccerSeasonTeamsRequest) Do() (s TeamList, err error) { d, _, err := r.doJson("GET") @@ -13,6 +17,8 @@ func (r SoccerSeasonTeamsRequest) Do() (s TeamList, err error) { return } +// DEPRECATED. +// // TeamsOfSoccerSeason prepares a new request to fetch the league table of a given soccer season. func (c *Client) TeamsOfSoccerSeason(soccerSeasonId uint64) SoccerSeasonTeamsRequest { return SoccerSeasonTeamsRequest{c.req("soccerseasons/%d/leagueTable", soccerSeasonId)} diff --git a/req_soccerseasons.go b/req_soccerseasons.go index 88d0fe7..bd61a82 100644 --- a/req_soccerseasons.go +++ b/req_soccerseasons.go @@ -2,14 +2,20 @@ package footballdata import "fmt" +// DEPRECATED. +// type SoccerSeasonsRequest struct{ request } +// DEPRECATED. +// // Season modifies the request to specify a season. func (r SoccerSeasonsRequest) Season(num uint32) SoccerSeasonsRequest { r.urlValues.Set("season", fmt.Sprintf("%d", num)) return r } +// DEPRECATED. +// // Do executes the request. func (r SoccerSeasonsRequest) Do() (s SoccerSeasonList, err error) { d, _, err := r.doJson("GET") @@ -21,6 +27,8 @@ func (r SoccerSeasonsRequest) Do() (s SoccerSeasonList, err error) { return } +// DEPRECATED. +// // SoccerSeasons prepares a request to fetch the complete list of soccer seasons. func (c *Client) SoccerSeasons() SoccerSeasonsRequest { return SoccerSeasonsRequest{c.req("soccerseasons")}