/
teams.go
87 lines (74 loc) · 2.84 KB
/
teams.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
package football
import (
"context"
"errors"
"fmt"
)
// TeamService provides methods for accessing information
// about teams.
type TeamService service
// Team represents data about a Team
type Team struct {
ID int `json:"id,omitempty"`
Area *Area `json:"area,omitempty"`
ActiveCompetitions *[]Competition `json:"activeCompetitions,omitempty"`
Name string `json:"name,omitempty"`
ShortName string `json:"shortName,omitempty"`
Tla string `json:"tla,omitempty"`
CrestURL string `json:"crestUrl,omitempty"`
Address string `json:"address,omitempty"`
Phone string `json:"phone,omitempty"`
Website string `json:"website,omitempty"`
Email string `json:"email,omitempty"`
Founded int `json:"founded,omitempty"`
ClubColors string `json:"clubColors,omitempty"`
Venue string `json:"venue,omitempty"`
Coach *Coach `json:"coach,omitempty"`
Captain *Player `json:"captain,omitempty"`
Squad *[]Player `json:"squad,omitempty"`
Lineup *[]Player `json:"lineup,omitempty"`
Bench *[]Player `json:"bench,omitempty"`
LastUpdated string `json:"lastUpdated,omitempty"`
}
// TeamMatches represents a collection of Matches for
// a Team
type TeamMatches struct {
Count int `json:"count,omitempty"`
Filters map[string]interface{} `json:"filters,omitempty"`
Matches []Match `json:"matches,omitempty"`
}
type TeamMatchesFiltersOptions struct {
DateFrom string `json:"dateFrom,omitempty"`
DateTo string `json:"dateTo,omitempty"`
Status string `json:"status,omitempty"`
Venue string `json:"venue,omitempty"`
Limit int64 `json:"limit,omitempty"`
}
// Find takes a Team ID and returns the corresponding Team
// for that ID.
// https://www.football-data.org/documentation/api
func (s *TeamService) Find(ctx context.Context, id string) (*Team, error) {
if len(id) == 0 {
return nil, errors.New("Team ID is required")
}
team := &Team{}
_, err := s.client.Get(fmt.Sprintf("teams/%s", id), nil, &team)
if err != nil {
return nil, err
}
return team, nil
}
// Matches takes a Team ID and returns a
// collection of all Matches for that Team.
// https://www.football-data.org/documentation/api
func (s *TeamService) Matches(ctx context.Context, id string, filters *TeamMatchesFiltersOptions) (*TeamMatches, error) {
if len(id) == 0 {
return nil, errors.New("Team ID is required")
}
teamMatches := &TeamMatches{}
_, err := s.client.Get(fmt.Sprintf("teams/%s/matches", id), filters, &teamMatches)
if err != nil {
return nil, err
}
return teamMatches, nil
}