mlbstats/api/api_season.go

441 lines
13 KiB
Go

/*
Copyright © 2025 filifa
This program is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
Stats API Documentation
Official API for Major League Baseball.
API version: 2.0.0
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package api
import (
"bytes"
"context"
"io"
"net/http"
"net/url"
"strings"
)
// SeasonAPIService SeasonAPI service
type SeasonAPIService service
type ApiAllSeasonsRequest struct {
ctx context.Context
ApiService *SeasonAPIService
divisionId *interface{}
leagueId *interface{}
sportId *interface{}
withGameTypeDates *interface{}
fields *interface{}
}
// Unique Division Identifier
func (r ApiAllSeasonsRequest) DivisionId(divisionId interface{}) ApiAllSeasonsRequest {
r.divisionId = &divisionId
return r
}
// Unique League Identifier
func (r ApiAllSeasonsRequest) LeagueId(leagueId interface{}) ApiAllSeasonsRequest {
r.leagueId = &leagueId
return r
}
// Top level organization of a sport
func (r ApiAllSeasonsRequest) SportId(sportId interface{}) ApiAllSeasonsRequest {
r.sportId = &sportId
return r
}
// Retrieve dates for each game type
func (r ApiAllSeasonsRequest) WithGameTypeDates(withGameTypeDates interface{}) ApiAllSeasonsRequest {
r.withGameTypeDates = &withGameTypeDates
return r
}
// Comma delimited list of specific fields to be returned. Format: topLevelNode, childNode, attribute
func (r ApiAllSeasonsRequest) Fields(fields interface{}) ApiAllSeasonsRequest {
r.fields = &fields
return r
}
func (r ApiAllSeasonsRequest) Execute() (*http.Response, error) {
return r.ApiService.AllSeasonsExecute(r)
}
/*
AllSeasons View all seasons
This endpoint allows you to view all seasons for a given Division, League or Sport
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
@return ApiAllSeasonsRequest
*/
func (a *SeasonAPIService) AllSeasons(ctx context.Context) ApiAllSeasonsRequest {
return ApiAllSeasonsRequest{
ApiService: a,
ctx: ctx,
}
}
// Execute executes the request
func (a *SeasonAPIService) AllSeasonsExecute(r ApiAllSeasonsRequest) (*http.Response, error) {
var (
localVarHTTPMethod = http.MethodGet
localVarPostBody interface{}
formFiles []formFile
)
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "SeasonAPIService.AllSeasons")
if err != nil {
return nil, &GenericOpenAPIError{error: err.Error()}
}
localVarPath := localBasePath + "/api/v1/seasons/all"
localVarHeaderParams := make(map[string]string)
localVarQueryParams := url.Values{}
localVarFormParams := url.Values{}
if r.divisionId != nil {
parameterAddToHeaderOrQuery(localVarQueryParams, "divisionId", r.divisionId, "", "")
}
if r.leagueId != nil {
parameterAddToHeaderOrQuery(localVarQueryParams, "leagueId", r.leagueId, "", "")
}
if r.sportId != nil {
parameterAddToHeaderOrQuery(localVarQueryParams, "sportId", r.sportId, "", "")
}
if r.withGameTypeDates != nil {
parameterAddToHeaderOrQuery(localVarQueryParams, "withGameTypeDates", r.withGameTypeDates, "", "")
}
if r.fields != nil {
parameterAddToHeaderOrQuery(localVarQueryParams, "fields", r.fields, "", "")
}
// to determine the Content-Type header
localVarHTTPContentTypes := []string{}
// set Content-Type header
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
if localVarHTTPContentType != "" {
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
}
// to determine the Accept header
localVarHTTPHeaderAccepts := []string{}
// set Accept header
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
if localVarHTTPHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
}
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
if err != nil {
return nil, err
}
localVarHTTPResponse, err := a.client.callAPI(req)
if err != nil || localVarHTTPResponse == nil {
return localVarHTTPResponse, err
}
localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
localVarHTTPResponse.Body.Close()
localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
if err != nil {
return localVarHTTPResponse, err
}
if localVarHTTPResponse.StatusCode >= 300 {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: localVarHTTPResponse.Status,
}
return localVarHTTPResponse, newErr
}
return localVarHTTPResponse, nil
}
type ApiSeasonsRequest struct {
ctx context.Context
ApiService *SeasonAPIService
seasonId interface{}
season *interface{}
sportId *interface{}
withGameTypeDates *interface{}
fields *interface{}
}
// Season of play
func (r ApiSeasonsRequest) Season(season interface{}) ApiSeasonsRequest {
r.season = &season
return r
}
// Top level organization of a sport
func (r ApiSeasonsRequest) SportId(sportId interface{}) ApiSeasonsRequest {
r.sportId = &sportId
return r
}
// Retrieve dates for each game type
func (r ApiSeasonsRequest) WithGameTypeDates(withGameTypeDates interface{}) ApiSeasonsRequest {
r.withGameTypeDates = &withGameTypeDates
return r
}
// Comma delimited list of specific fields to be returned. Format: topLevelNode, childNode, attribute
func (r ApiSeasonsRequest) Fields(fields interface{}) ApiSeasonsRequest {
r.fields = &fields
return r
}
func (r ApiSeasonsRequest) Execute() (*http.Response, error) {
return r.ApiService.SeasonsExecute(r)
}
/*
Seasons View season info
This endpoint allows you to pull seasons
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
@param seasonId Season of play
@return ApiSeasonsRequest
*/
func (a *SeasonAPIService) Seasons(ctx context.Context, seasonId interface{}) ApiSeasonsRequest {
return ApiSeasonsRequest{
ApiService: a,
ctx: ctx,
seasonId: seasonId,
}
}
// Execute executes the request
func (a *SeasonAPIService) SeasonsExecute(r ApiSeasonsRequest) (*http.Response, error) {
var (
localVarHTTPMethod = http.MethodGet
localVarPostBody interface{}
formFiles []formFile
)
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "SeasonAPIService.Seasons")
if err != nil {
return nil, &GenericOpenAPIError{error: err.Error()}
}
localVarPath := localBasePath + "/api/v1/seasons"
localVarPath = strings.Replace(localVarPath, "{"+"seasonId"+"}", url.PathEscape(parameterValueToString(r.seasonId, "seasonId")), -1)
localVarHeaderParams := make(map[string]string)
localVarQueryParams := url.Values{}
localVarFormParams := url.Values{}
if r.season != nil {
parameterAddToHeaderOrQuery(localVarQueryParams, "season", r.season, "", "")
}
if r.sportId != nil {
parameterAddToHeaderOrQuery(localVarQueryParams, "sportId", r.sportId, "", "")
}
if r.withGameTypeDates != nil {
parameterAddToHeaderOrQuery(localVarQueryParams, "withGameTypeDates", r.withGameTypeDates, "", "")
}
if r.fields != nil {
parameterAddToHeaderOrQuery(localVarQueryParams, "fields", r.fields, "", "")
}
// to determine the Content-Type header
localVarHTTPContentTypes := []string{}
// set Content-Type header
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
if localVarHTTPContentType != "" {
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
}
// to determine the Accept header
localVarHTTPHeaderAccepts := []string{}
// set Accept header
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
if localVarHTTPHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
}
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
if err != nil {
return nil, err
}
localVarHTTPResponse, err := a.client.callAPI(req)
if err != nil || localVarHTTPResponse == nil {
return localVarHTTPResponse, err
}
localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
localVarHTTPResponse.Body.Close()
localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
if err != nil {
return localVarHTTPResponse, err
}
if localVarHTTPResponse.StatusCode >= 300 {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: localVarHTTPResponse.Status,
}
return localVarHTTPResponse, newErr
}
return localVarHTTPResponse, nil
}
type ApiSeasons1Request struct {
ctx context.Context
ApiService *SeasonAPIService
seasonId interface{}
season *interface{}
sportId *interface{}
withGameTypeDates *interface{}
fields *interface{}
}
// Season of play
func (r ApiSeasons1Request) Season(season interface{}) ApiSeasons1Request {
r.season = &season
return r
}
// Top level organization of a sport
func (r ApiSeasons1Request) SportId(sportId interface{}) ApiSeasons1Request {
r.sportId = &sportId
return r
}
// Retrieve dates for each game type
func (r ApiSeasons1Request) WithGameTypeDates(withGameTypeDates interface{}) ApiSeasons1Request {
r.withGameTypeDates = &withGameTypeDates
return r
}
// Comma delimited list of specific fields to be returned. Format: topLevelNode, childNode, attribute
func (r ApiSeasons1Request) Fields(fields interface{}) ApiSeasons1Request {
r.fields = &fields
return r
}
func (r ApiSeasons1Request) Execute() (*http.Response, error) {
return r.ApiService.Seasons1Execute(r)
}
/*
Seasons1 View season info
This endpoint allows you to pull seasons
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
@param seasonId Season of play
@return ApiSeasons1Request
*/
func (a *SeasonAPIService) Seasons1(ctx context.Context, seasonId interface{}) ApiSeasons1Request {
return ApiSeasons1Request{
ApiService: a,
ctx: ctx,
seasonId: seasonId,
}
}
// Execute executes the request
func (a *SeasonAPIService) Seasons1Execute(r ApiSeasons1Request) (*http.Response, error) {
var (
localVarHTTPMethod = http.MethodGet
localVarPostBody interface{}
formFiles []formFile
)
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "SeasonAPIService.Seasons1")
if err != nil {
return nil, &GenericOpenAPIError{error: err.Error()}
}
localVarPath := localBasePath + "/api/v1/seasons/{seasonId}"
localVarPath = strings.Replace(localVarPath, "{"+"seasonId"+"}", url.PathEscape(parameterValueToString(r.seasonId, "seasonId")), -1)
localVarHeaderParams := make(map[string]string)
localVarQueryParams := url.Values{}
localVarFormParams := url.Values{}
if r.season != nil {
parameterAddToHeaderOrQuery(localVarQueryParams, "season", r.season, "", "")
}
if r.sportId != nil {
parameterAddToHeaderOrQuery(localVarQueryParams, "sportId", r.sportId, "", "")
}
if r.withGameTypeDates != nil {
parameterAddToHeaderOrQuery(localVarQueryParams, "withGameTypeDates", r.withGameTypeDates, "", "")
}
if r.fields != nil {
parameterAddToHeaderOrQuery(localVarQueryParams, "fields", r.fields, "", "")
}
// to determine the Content-Type header
localVarHTTPContentTypes := []string{}
// set Content-Type header
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
if localVarHTTPContentType != "" {
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
}
// to determine the Accept header
localVarHTTPHeaderAccepts := []string{}
// set Accept header
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
if localVarHTTPHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
}
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
if err != nil {
return nil, err
}
localVarHTTPResponse, err := a.client.callAPI(req)
if err != nil || localVarHTTPResponse == nil {
return localVarHTTPResponse, err
}
localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
localVarHTTPResponse.Body.Close()
localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
if err != nil {
return localVarHTTPResponse, err
}
if localVarHTTPResponse.StatusCode >= 300 {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: localVarHTTPResponse.Status,
}
return localVarHTTPResponse, newErr
}
return localVarHTTPResponse, nil
}