add date param

This commit is contained in:
filifa 2024-07-28 15:16:01 -05:00
parent 6a8e39a431
commit 366e55146a
2 changed files with 8 additions and 5 deletions

View File

@ -26,8 +26,8 @@ import (
var DefaultClient = NewClient(http.DefaultClient)
func RequestSchedule(sportId, teamId string) ([]byte, error) {
return DefaultClient.RequestSchedule(sportId, teamId)
func RequestSchedule(sportId, teamId, date string) ([]byte, error) {
return DefaultClient.RequestSchedule(sportId, teamId, date)
}
func RequestFeed(gamePk string) ([]byte, error) {
@ -76,11 +76,12 @@ func (resp *DiffPatchResponse) ExtractPatches() ([]jsonpatch.Patch, error) {
return patches, err
}
func (c *Client) RequestSchedule(sportId, teamId string) ([]byte, error) {
func (c *Client) RequestSchedule(sportId, teamId, date string) ([]byte, error) {
endpoint := url.URL{Path: "api/v1/schedule"}
query := endpoint.Query()
query.Add("sportId", sportId)
query.Add("teamId", teamId)
query.Add("date", date)
endpoint.RawQuery = query.Encode()
return c.get(&endpoint)

View File

@ -26,6 +26,7 @@ import (
)
var team teamFlag
var date string
var teamIDs = map[string]statsapi.TeamID{
"laa": statsapi.LAA,
"az": statsapi.AZ,
@ -67,7 +68,7 @@ func schedule(cmd *cobra.Command, args []string) {
id = strconv.Itoa(int(teamIDs[string(team)]))
}
sched, err := statsapi.RequestSchedule("1", id)
sched, err := statsapi.RequestSchedule("1", id, date)
if err != nil {
log.Fatal(err)
}
@ -95,5 +96,6 @@ func init() {
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
scheduleCmd.Flags().VarP(&team, "team", "t", "team to get updates for (atl, az, bal, bos, chc, cin, cle, col, cws, det, hou, kc, laa, lad, mia, mil, min, nym, nyy, oak, phi, pit, sd, sea, sf, stl, tb, tex, tor, wsh)")
scheduleCmd.Flags().VarP(&team, "team", "t", "team to get schedule for (atl, az, bal, bos, chc, cin, cle, col, cws, det, hou, kc, laa, lad, mia, mil, min, nym, nyy, oak, phi, pit, sd, sea, sf, stl, tb, tex, tor, wsh)")
scheduleCmd.Flags().StringVarP(&date, "date", "d", "", "date to get schedule for (YYYY-MM-DD)")
}