diff --git a/cmd/schedule.go b/cmd/schedule.go index d5ecacd..b14a907 100644 --- a/cmd/schedule.go +++ b/cmd/schedule.go @@ -18,8 +18,8 @@ package cmd import ( "context" - "encoding/json" "fmt" + "io" "log" "github.com/spf13/cobra" @@ -33,24 +33,31 @@ var sport = sportAbbr("mlb") func schedule(cmd *cobra.Command, args []string) { sportId := int32(sportIDs[string(sport)]) - client := api.NewAPIClient(api.NewConfiguration()) + cfg := api.NewConfiguration() + cfg.Host = "statsapi.mlb.com" + cfg.Scheme = "https" + + client := api.NewAPIClient(cfg) req := client.ScheduleAPI.Schedule(context.Background()) - req.SportId(sportId) - req.TeamId(teamIDs[string(team)]) - req.Date(date) + req = req.SportId(sportId) + req = req.Date(date) + req = req.UsingPrivateEndpoint(false) + if team != "" { + req = req.TeamId(teamIDs[string(team)]) + } resp, err := req.Execute() if err != nil { log.Fatal(err) } - json, err := json.Marshal(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { log.Fatal(err) } - fmt.Println(string(json)) + fmt.Println(string(body)) } // scheduleCmd represents the schedule command