mlbstats/api/api_transactions.go

237 lines
6.7 KiB
Go

/*
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"
)
// TransactionsAPIService TransactionsAPI service
type TransactionsAPIService service
type ApiTransactionsRequest struct {
ctx context.Context
ApiService *TransactionsAPIService
leagueId *interface{}
sportId *interface{}
teamId *interface{}
playerId *interface{}
date *interface{}
startDate *interface{}
endDate *interface{}
transactionIds *interface{}
transactionTypes *interface{}
divisionIds *interface{}
order *interface{}
limit *interface{}
fields *interface{}
}
// Comma delimited list of Unique league identifiers
func (r ApiTransactionsRequest) LeagueId(leagueId interface{}) ApiTransactionsRequest {
r.leagueId = &leagueId
return r
}
// Comma delimited list of top level organizations of a sport
func (r ApiTransactionsRequest) SportId(sportId interface{}) ApiTransactionsRequest {
r.sportId = &sportId
return r
}
// Comma delimited list of Unique Team identifiers
func (r ApiTransactionsRequest) TeamId(teamId interface{}) ApiTransactionsRequest {
r.teamId = &teamId
return r
}
// A unique identifier for a player
func (r ApiTransactionsRequest) PlayerId(playerId interface{}) ApiTransactionsRequest {
r.playerId = &playerId
return r
}
// Date of Game. Format: YYYY-MM-DD
func (r ApiTransactionsRequest) Date(date interface{}) ApiTransactionsRequest {
r.date = &date
return r
}
// Start date for range of data (must be used with end date). Format: MM/DD/YYYY
func (r ApiTransactionsRequest) StartDate(startDate interface{}) ApiTransactionsRequest {
r.startDate = &startDate
return r
}
// End date for range of data (must be used with start date). Format: MM/DD/YYYY
func (r ApiTransactionsRequest) EndDate(endDate interface{}) ApiTransactionsRequest {
r.endDate = &endDate
return r
}
func (r ApiTransactionsRequest) TransactionIds(transactionIds interface{}) ApiTransactionsRequest {
r.transactionIds = &transactionIds
return r
}
func (r ApiTransactionsRequest) TransactionTypes(transactionTypes interface{}) ApiTransactionsRequest {
r.transactionTypes = &transactionTypes
return r
}
func (r ApiTransactionsRequest) DivisionIds(divisionIds interface{}) ApiTransactionsRequest {
r.divisionIds = &divisionIds
return r
}
func (r ApiTransactionsRequest) Order(order interface{}) ApiTransactionsRequest {
r.order = &order
return r
}
func (r ApiTransactionsRequest) Limit(limit interface{}) ApiTransactionsRequest {
r.limit = &limit
return r
}
// Comma delimited list of specific fields to be returned. Format: topLevelNode, childNode, attribute
func (r ApiTransactionsRequest) Fields(fields interface{}) ApiTransactionsRequest {
r.fields = &fields
return r
}
func (r ApiTransactionsRequest) Execute() (*http.Response, error) {
return r.ApiService.TransactionsExecute(r)
}
/*
Transactions View transaction info
This endpoint allows you to pull transactions.
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
@return ApiTransactionsRequest
*/
func (a *TransactionsAPIService) Transactions(ctx context.Context) ApiTransactionsRequest {
return ApiTransactionsRequest{
ApiService: a,
ctx: ctx,
}
}
// Execute executes the request
func (a *TransactionsAPIService) TransactionsExecute(r ApiTransactionsRequest) (*http.Response, error) {
var (
localVarHTTPMethod = http.MethodGet
localVarPostBody interface{}
formFiles []formFile
)
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "TransactionsAPIService.Transactions")
if err != nil {
return nil, &GenericOpenAPIError{error: err.Error()}
}
localVarPath := localBasePath + "/api/v1/transactions"
localVarHeaderParams := make(map[string]string)
localVarQueryParams := url.Values{}
localVarFormParams := url.Values{}
if r.leagueId != nil {
parameterAddToHeaderOrQuery(localVarQueryParams, "leagueId", r.leagueId, "", "")
}
if r.sportId != nil {
parameterAddToHeaderOrQuery(localVarQueryParams, "sportId", r.sportId, "", "")
}
if r.teamId != nil {
parameterAddToHeaderOrQuery(localVarQueryParams, "teamId", r.teamId, "", "")
}
if r.playerId != nil {
parameterAddToHeaderOrQuery(localVarQueryParams, "playerId", r.playerId, "", "")
}
if r.date != nil {
parameterAddToHeaderOrQuery(localVarQueryParams, "date", r.date, "", "")
}
if r.startDate != nil {
parameterAddToHeaderOrQuery(localVarQueryParams, "startDate", r.startDate, "", "")
}
if r.endDate != nil {
parameterAddToHeaderOrQuery(localVarQueryParams, "endDate", r.endDate, "", "")
}
if r.transactionIds != nil {
parameterAddToHeaderOrQuery(localVarQueryParams, "transactionIds", r.transactionIds, "", "")
}
if r.transactionTypes != nil {
parameterAddToHeaderOrQuery(localVarQueryParams, "transactionTypes", r.transactionTypes, "", "")
}
if r.divisionIds != nil {
parameterAddToHeaderOrQuery(localVarQueryParams, "divisionIds", r.divisionIds, "", "")
}
if r.order != nil {
parameterAddToHeaderOrQuery(localVarQueryParams, "order", r.order, "", "")
}
if r.limit != nil {
parameterAddToHeaderOrQuery(localVarQueryParams, "limit", r.limit, "", "")
}
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
}