go-footballdata/req_fixtures.go

53 lines
1.5 KiB
Go
Raw Normal View History

2016-06-12 22:39:00 +00:00
package footballdata
import (
"strings"
"time"
)
type FixturesRequest struct{ request }
// TimeFrame modifies the request to specify a specific relative time frame.
2016-06-12 22:39:00 +00:00
func (r FixturesRequest) TimeFrame(timeframe time.Duration) FixturesRequest {
r.urlValues.Set("timeFrame", durationToTimeFrame(timeframe))
2016-06-12 22:39:00 +00:00
return r
}
// TimeFrameStart modifies the request to specify the beginning of the time frame filter for the returned results.
//
// Only the year, month and day of the Time value will be used for the request.
func (r FixturesRequest) TimeFrameStart(date time.Time) FixturesRequest {
r.urlValues.Set("timeFrameStart", date.Format(timeFrameLayout))
return r
}
// TimeFrameEnd modifies the request to specify the end of the time frame filter for the returned results.
//
// Only the year, month and day of the Time value will be used for the request.
2016-07-09 19:46:45 +00:00
func (r FixturesRequest) TimeFrameEnd(date time.Time) FixturesRequest {
r.urlValues.Set("timeFrameEnd", date.Format(timeFrameLayout))
return r
}
// League modifies the request to specify a list of leagues by their code.
2016-06-12 22:39:00 +00:00
func (r FixturesRequest) League(leagueCodes ...string) FixturesRequest {
r.urlValues.Set("league", strings.Join(leagueCodes, ","))
2016-06-12 22:39:00 +00:00
return r
}
// Do executes the request.
2016-06-12 22:39:00 +00:00
func (r FixturesRequest) Do() (s FixturesResponse, err error) {
d, _, err := r.doJson("GET")
if err != nil {
return
}
err = d.Decode(&s)
return
}
// Fixtures prepares a request to fetch the fixtures of a soccer season.
func (c *Client) Fixtures() FixturesRequest {
2016-06-12 22:39:00 +00:00
return FixturesRequest{c.req("fixtures")}
}