Implement "timeFrameStart" and "timeFrameEnd" filters for fixtures.

develop
Icedream 2016-07-09 21:41:55 +02:00
parent eeff7fb54b
commit daa2878117
Signed by: icedream
GPG Key ID: 1573F6D8EFE4D0CF
3 changed files with 36 additions and 2 deletions

View File

@ -13,12 +13,28 @@ func (r CompetitionFixturesRequest) Matchday(matchday uint16) CompetitionFixture
return r
}
// TimeFrame modifies the request to specify a specific time frame.
// TimeFrame modifies the request to specify a specific relative time frame.
func (r CompetitionFixturesRequest) TimeFrame(timeframe time.Duration) CompetitionFixturesRequest {
r.urlValues.Set("timeFrame", durationToTimeFrame(timeframe))
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 CompetitionFixturesRequest) TimeFrameStart(date time.Time) CompetitionFixturesRequest {
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.
func (r CompetitionFixturesRequest) TimeFrameStart(date time.Time) CompetitionFixturesRequest {
r.urlValues.Set("timeFrameEnd", date.Format(timeFrameLayout))
return r
}
// Do executes the request.
func (r CompetitionFixturesRequest) Do() (s FixtureList, err error) {
d, _, err := r.doJson("GET")

View File

@ -7,12 +7,28 @@ import (
type FixturesRequest struct{ request }
// TimeFrame modifies the request to specify a specific time frame.
// TimeFrame modifies the request to specify a specific relative time frame.
func (r FixturesRequest) TimeFrame(timeframe time.Duration) FixturesRequest {
r.urlValues.Set("timeFrame", durationToTimeFrame(timeframe))
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.
func (r FixturesRequest) TimeFrameStart(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.
func (r FixturesRequest) League(leagueCodes ...string) FixturesRequest {
r.urlValues.Set("league", strings.Join(leagueCodes, ","))

View File

@ -8,6 +8,8 @@ import (
const (
day = 24 * time.Hour
week = 7 * day
timeFrameLayout = "2006-01-02"
)
func durationToTimeFrame(d time.Duration) (r string) {