-
Notifications
You must be signed in to change notification settings - Fork 0
/
players.go
96 lines (87 loc) · 2.87 KB
/
players.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
89
90
91
92
93
94
95
96
package nba
import (
"strings"
)
type Players struct {
Internal Internal `json:"_internal"`
Leagues map[string][]ActivePlayer `json:"league"`
}
type ActivePlayer struct {
FirstName string `json:"firstName,omitempty"`
LastName string `json:"lastName,omitempty"`
PersonID string `json:"personId,omitempty"`
TeamID string `json:"teamId,omitempty"`
IsOnCourt bool `json:"isOnCourt,omitempty"`
Points string `json:"points"`
Position string `json:"pos,omitempty"`
Minutes string `json:"min"`
Fgm string `json:"fgm"`
Fga string `json:"fga"`
Fgp string `json:"fgp"`
Ftm string `json:"ftm"`
Fta string `json:"fta"`
Ftp string `json:"ftp"`
Tpm string `json:"tpm"`
Tpa string `json:"tpa"`
Tpp string `json:"tpp"`
OffReb string `json:"offReb"`
DefReb string `json:"defReb"`
TotReb string `json:"totReb"`
Assists string `json:"assists"`
PFouls string `json:"pFouls"`
Steals string `json:"steals"`
Turnovers string `json:"turnovers"`
Blocks string `json:"blocks"`
PlusMinus string `json:"plusMinus"`
Dnp string `json:"dnp,omitempty"`
SortKey map[string]int64 `json:"sortKey,omitempty"`
}
type Leader struct {
Players []Player `json:"players"`
Value int `json:"value"`
}
type Player struct {
CollegeName string `json:"collegeName"`
Country string `json:"country"`
DateOfBirthUTC string `json:"dateOfBirthUTC"`
FirstName string `json:"firstName"`
HeightFeet string `json:"heightFeet"`
HeightInches string `json:"heightInches"`
IsActive bool `json:"isActive"`
Jersey string `json:"jersey"`
LastAffiliation string `json:"lastAffiliation"`
LastName string `json:"lastName"`
NbaDebutYear string `json:"nbaDebutYear"`
PersonID string `json:"personId"`
TeamID string `json:"teamId"`
WeightPounds string `json:"weightPounds"`
WeightKilograms string `json:"weightKilograms"`
YearsPro string `json:"yearsPro"`
}
func (a *ActivePlayer) GetPosition() string {
switch strings.ToUpper(a.Position) {
case "C":
return "Center"
case "PG":
return "Point Guard"
case "PF":
return "Power Forward"
case "SF":
return "Small Forward"
case "SG":
return "Shooting Guard"
default:
return "N/A"
}
}
func GetActivePlayers(league string) map[string]ActivePlayer {
// endpoint:
// v1/2021/players.json
var players Players
mappedPlayers := make(map[string]ActivePlayer)
httpRequest("v1/2021/players.json", &players)
for _, player := range players.Leagues[league] {
mappedPlayers[player.PersonID] = player
}
return mappedPlayers
}