-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support further endpoints and simplify boilerplate code
- Loading branch information
Showing
14 changed files
with
756 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package endpoints | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/url" | ||
"time" | ||
) | ||
|
||
type Injury struct { | ||
PlayerID int `json:"player_id"` | ||
PlayerName string `json:"player_name"` | ||
PlayerHashImage string `json:"player_hash_image"` | ||
Type string `json:"type"` | ||
Reason string `json:"reason"` | ||
MatchID int `json:"match_id"` | ||
SeasonID int `json:"season_id"` | ||
TournamentID int `json:"tournament_id"` | ||
StartTimestamp time.Time `json:"start_timestamp"` | ||
} | ||
|
||
const Injuries = "injuries" | ||
|
||
func (client *RestClient) GetInjuriesByPlayerID(ctx context.Context, sport string, id int) ([]Injury, error) { | ||
return getInjuries(client, ctx, sport, "player_id", id) | ||
} | ||
|
||
func (client *RestClient) GetInjuriesByMatchID(ctx context.Context, sport string, id int) ([]Injury, error) { | ||
return getInjuries(client, ctx, sport, "match_id", id) | ||
} | ||
|
||
func (client *RestClient) GetInjuriesBySeasonID(ctx context.Context, sport string, id int) ([]Injury, error) { | ||
return getInjuries(client, ctx, sport, "season_id", id) | ||
} | ||
|
||
func (client *RestClient) GetInjuriesByTournamentID(ctx context.Context, sport string, id int) ([]Injury, error) { | ||
return getInjuries(client, ctx, sport, "tournament_id", id) | ||
} | ||
|
||
func getInjuries(client *RestClient, ctx context.Context, sport string, query string, id int) ([]Injury, error) { | ||
injuries := []Injury{} | ||
|
||
values := url.Values{} | ||
values.Set(query, fmt.Sprintf("eq.%v", id)) | ||
|
||
err := Get(client, ctx, sport, Injuries, values, &injuries) | ||
|
||
return injuries, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package endpoints | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/url" | ||
"time" | ||
) | ||
|
||
type Media struct { | ||
ID int `json:"id"` | ||
TeamID int `json:"team_id,omitempty"` | ||
PlayerID int `json:"player_id,omitempty"` | ||
LeagueID int `json:"league_id,omitempty"` | ||
Title string `json:"title"` | ||
Subtitle string `json:"subtitle"` | ||
URL string `json:"url"` | ||
ThumbnailURL string `json:"thumbnail_url"` | ||
DatePublished time.Time `json:"date_published"` | ||
ChannelURL string `json:"channel_url"` | ||
} | ||
|
||
const ( | ||
MediaTeams = "media-teams" | ||
MediaPlayers = "media-players" | ||
MediaLeagues = "media-leagues" | ||
) | ||
|
||
func (client *RestClient) GetMediaByTeamID(ctx context.Context, sport string, id int) ([]Media, error) { | ||
return getMedia(client, ctx, sport, MediaTeams, "team_id", id) | ||
} | ||
|
||
func (client *RestClient) GetMediaByPlayerID(ctx context.Context, sport string, id int) ([]Media, error) { | ||
return getMedia(client, ctx, sport, MediaPlayers, "player_id", id) | ||
} | ||
|
||
func (client *RestClient) GetMediaByLeagueID(ctx context.Context, sport string, id int) ([]Media, error) { | ||
return getMedia(client, ctx, sport, MediaLeagues, "league_id", id) | ||
} | ||
|
||
func getMedia(client *RestClient, ctx context.Context, sport string, resource string, query string, id int) ([]Media, error) { | ||
media := []Media{} | ||
|
||
values := url.Values{} | ||
values.Set(query, fmt.Sprintf("eq.%v", id)) | ||
|
||
err := Get(client, ctx, sport, resource, values, &media) | ||
|
||
return media, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package endpoints | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/url" | ||
"time" | ||
) | ||
|
||
type ( | ||
Subtitle struct { | ||
Text string `json:"text"` | ||
Subtitle string `json:"subtitle"` | ||
} | ||
|
||
News struct { | ||
MatchID int `json:"match_id"` | ||
Date time.Time `json:"date"` | ||
Title string `json:"title"` | ||
Subtitles []Subtitle `json:"subtitles"` | ||
} | ||
) | ||
|
||
type AggNews struct { | ||
ID int `json:"id"` | ||
TeamID int `json:"team_id,omitempty"` | ||
MatchID int `json:"match_id,omitempty"` | ||
PlayerID int `json:"player_id,omitempty"` | ||
LeagueID int `json:"league_id,omitempty"` | ||
Title string `json:"title"` | ||
Link string `json:"link"` | ||
ThumbnailURL string `json:"thumbnail_url"` | ||
Description string `json:"description"` | ||
PublishedDate time.Time `json:"published_date"` | ||
SourceURL string `json:"source_url"` | ||
Source string `json:"source"` | ||
} | ||
|
||
const ( | ||
NewsMatches = "news-matches" | ||
AggNewsTeams = "news-agg-teams" | ||
AggNewsMatches = "news-agg-matches" | ||
AggNewsLeagues = "news-agg-leagues" | ||
AggNewsPlayers = "news-agg-players" | ||
) | ||
|
||
func (client *RestClient) GetNewsByMatchID(ctx context.Context, sport string, id int) ([]News, error) { | ||
news := []News{} | ||
|
||
values := url.Values{} | ||
values.Set("match_id", fmt.Sprintf("eq.%v", id)) | ||
|
||
err := Get(client, ctx, sport, NewsMatches, values, &news) | ||
|
||
return news, err | ||
} | ||
|
||
func (client *RestClient) GetAggNewsByTeamID(ctx context.Context, sport string, id int) ([]AggNews, error) { | ||
return getAggNews(client, ctx, sport, AggNewsTeams, "team_id", id) | ||
} | ||
|
||
func (client *RestClient) GetAggNewsByMatchID(ctx context.Context, sport string, id int) ([]AggNews, error) { | ||
return getAggNews(client, ctx, sport, AggNewsMatches, "match_id", id) | ||
} | ||
|
||
func (client *RestClient) GetAggNewsByLeagueID(ctx context.Context, sport string, id int) ([]AggNews, error) { | ||
return getAggNews(client, ctx, sport, AggNewsLeagues, "league_id", id) | ||
} | ||
|
||
func (client *RestClient) GetAggNewsByPlayerID(ctx context.Context, sport string, id int) ([]AggNews, error) { | ||
return getAggNews(client, ctx, sport, AggNewsPlayers, "player_id", id) | ||
} | ||
|
||
func getAggNews(client *RestClient, ctx context.Context, sport string, resource string, query string, id int) ([]AggNews, error) { | ||
news := []AggNews{} | ||
|
||
values := url.Values{} | ||
values.Set(query, fmt.Sprintf("eq.%v", id)) | ||
|
||
err := Get(client, ctx, sport, resource, values, &news) | ||
|
||
return news, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package endpoints | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/url" | ||
) | ||
|
||
type ( | ||
Competitor struct { | ||
Wins int `json:"wins"` | ||
Draws int `json:"draws"` | ||
Losses int `json:"losses"` | ||
Points int `json:"points"` | ||
Matches int `json:"matches"` | ||
TeamID int `json:"team_id"` | ||
Position int `json:"position"` | ||
TeamName string `json:"team_name"` | ||
ScoresFor int `json:"scores_for"` | ||
ScoresAgainst int `json:"scores_against"` | ||
TeamHashImage string `json:"team_hash_image"` | ||
} | ||
|
||
Standing struct { | ||
ID int `json:"id"` | ||
TournamentID int `json:"tournament_id"` | ||
Type string `json:"type"` | ||
Name string `json:"name"` | ||
SeasonID int `json:"season_id"` | ||
SeasonName string `json:"season_name"` | ||
LeagueID int `json:"league_id"` | ||
LeagueName string `json:"league_name"` | ||
LeagueHashImage string `json:"league_hash_image"` | ||
Competitors []Competitor `json:"competitors"` | ||
} | ||
) | ||
|
||
const Standings = "standings" | ||
|
||
func (client *RestClient) GetStandings(ctx context.Context, sport string) ([]Standing, error) { | ||
return getStandings(client, ctx, sport, "", nil) | ||
} | ||
|
||
func (client *RestClient) GetStandingsByID(ctx context.Context, sport string, id int) ([]Standing, error) { | ||
return getStandings(client, ctx, sport, "id", id) | ||
} | ||
|
||
func (client *RestClient) GetStandingsByLeagueSeasonTypeID(ctx context.Context, sport string, id int, seasonID int, standingType string) ([]Standing, error) { | ||
standings := []Standing{} | ||
|
||
values := url.Values{} | ||
|
||
if id != 0 { | ||
values.Set("league_id", fmt.Sprintf("eq.%v", id)) | ||
} | ||
|
||
if seasonID != 0 { | ||
values.Set("season_id", fmt.Sprintf("eq.%v", seasonID)) | ||
} | ||
|
||
if standingType != "" { | ||
values.Set("type", fmt.Sprintf("eq.%v", standingType)) | ||
} | ||
|
||
err := Get(client, ctx, sport, Standings, values, &standings) | ||
|
||
return standings, err | ||
} | ||
|
||
func getStandings(client *RestClient, ctx context.Context, sport string, query string, id any) ([]Standing, error) { | ||
standings := []Standing{} | ||
|
||
values := url.Values{} | ||
if query != "" && id != nil { | ||
values.Set(query, fmt.Sprintf("eq.%v", id)) | ||
} | ||
|
||
err := Get(client, ctx, sport, Standings, values, &standings) | ||
|
||
return standings, err | ||
} |
Oops, something went wrong.