/
rounds.go
88 lines (70 loc) · 2.28 KB
/
rounds.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package sportmonks
import (
"context"
"fmt"
"net/url"
"strings"
)
// Round provides a struct representation of a Round resource.
type Round struct {
ID int `json:"id"`
Name int `json:"name"`
LeagueID int `json:"league_id"`
SeasonID int `json:"season_id"`
StageID int `json:"stage_id"`
Start string `json:"start"`
End string `json:"end"`
FixturesData FixturesData `json:"fixtures,omitempty"`
LeagueData LeagueData `json:"league"`
ResultsData FixturesData `json:"results,omitempty"`
SeasonData SeasonData `json:"season"`
}
// Fixtures returns a slice of Fixture struct associated to a Round.
func (r *Round) Fixtures() []Fixture {
return r.FixturesData.Data
}
// League returns a League struct associated to a Round.
func (r *Round) League() *League {
return r.LeagueData.Data
}
// Results returns a slice of completed Fixture struct associated to a Round.
func (r *Round) Results() []Fixture {
return r.ResultsData.Data
}
// Season returns a League struct associated to a Round.
func (r *Round) Season() *Season {
return r.SeasonData.Data
}
// RoundByID fetches a Round resource by ID. Use the includes slice of string to enrich the response data.
func (c *HTTPClient) RoundByID(ctx context.Context, id int, includes []string) (*Round, *Meta, error) {
path := fmt.Sprintf(roundsURI+"/%d", id)
values := url.Values{
"include": {strings.Join(includes, ",")},
}
response := struct {
Data *Round `json:"data"`
Meta *Meta `json:"meta"`
}{}
err := c.getResource(ctx, path, values, &response)
if err != nil {
return nil, nil, err
}
return response.Data, response.Meta, err
}
// RoundsBySeasonID fetches a Round resource associated to a Season by Season ID. Use the includes slice of string
// to enrich the response data.
func (c *HTTPClient) RoundsBySeasonID(ctx context.Context, id int, includes []string) ([]Round, *Meta, error) {
path := fmt.Sprintf(roundsSeasonURI+"/%d", id)
values := url.Values{
"include": {strings.Join(includes, ",")},
}
response := struct {
Data []Round `json:"data"`
Meta *Meta `json:"meta"`
}{}
err := c.getResource(ctx, path, values, &response)
if err != nil {
return nil, nil, err
}
return response.Data, response.Meta, err
}