-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_test.go
222 lines (206 loc) · 6.41 KB
/
example_test.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
package gonhl_test
import (
"fmt"
"github.com/henrymxu/gonhl"
"time"
)
func ExampleNewClient() {
client := gonhl.NewClient()
fmt.Println(client)
}
func ExampleClient_GetConference() {
client := gonhl.NewClient()
conference, _ := client.GetConference(6)
fmt.Println(conference.Name)
// Output: Eastern
}
func ExampleClient_GetDivision() {
client := gonhl.NewClient()
division, _ := client.GetDivision(18)
fmt.Println(division.Name)
// Output: Metropolitan
}
func ExampleClient_GetDraft() {
client := gonhl.NewClient()
draft, _ := client.GetDraft(2018)
fmt.Println(draft[0].DraftYear)
// Output: 2018
}
// Example of retrieving Player information.
// Information about Connor McDavid.
func ExampleClient_GetPlayer() {
client := gonhl.NewClient()
player, _ := client.GetPlayer(8478402)
fmt.Println(player.FullName)
fmt.Println(player.Height.Format())
fmt.Println(player.Weight)
fmt.Println(player.BirthDate.Format("2006-01-02"))
// Output:
// Connor McDavid
// 6' 1"
// 193
// 1997-01-13
}
// Example of retrieving Skater Stats.
// Stats for Connor McDavid point total in the 2017 season.
func ExampleClient_GetPlayerStats_skater() {
client := gonhl.NewClient()
playerParams := gonhl.NewPlayerParams().
SetId(8478402).
SetStat("statsSingleSeason").
SetSeason(2017)
player, _ := client.GetPlayerStats(playerParams)
fmt.Println(player[0].Type.DisplayName)
playerStat, _ := gonhl.ConvertPlayerStatsToSkaterStats(player[0].Splits[0].Stat)
fmt.Println(player[0].Splits[0].Season)
fmt.Println(playerStat.Points)
// Output:
// statsSingleSeason
// 20172018
// 108
}
// Example of retrieving Goalie Stats.
// Stats for Henrik Lundqvist save percentage and wins in the in progress 2018 season.
func ExampleClient_GetPlayerStats_goalie() {
client := gonhl.NewClient()
playerParams := gonhl.NewPlayerParams().
SetId(8468685).
SetStat("vsConference", "vsDivision").
SetSeason(2018)
player, _ := client.GetPlayerStats(playerParams)
fmt.Println(player[0].Type.DisplayName)
playerStat, _ := gonhl.ConvertPlayerStatsToGoalieStats(player[0].Splits[0].Stat)
fmt.Println(playerStat.SavePercentage > 0)
fmt.Println(playerStat.Saves > 0)
// Output:
// vsConference
// true
// true
}
// Example of retrieving multiple teams.
// Gets detailed roster, and stats (values and rank) for 3 NHL teams.
func ExampleClient_GetTeams() {
client := gonhl.NewClient()
teamsParams := gonhl.NewTeamsParams().
ShowDetailedRoster().
ShowTeamStats().
SetTeamIds(1, 2, 3)
teams, _ := client.GetTeams(teamsParams)
fmt.Println(teams[0].Name)
fmt.Println(teams[0].TeamStats[0].Type.DisplayName)
fmt.Println(teams[0].Roster.Link)
teamStat, _ := gonhl.ConvertTeamStatsToTeamStats(teams[0].TeamStats[0].Splits[0].Stat)
fmt.Println(teamStat.GamesPlayed > 0)
rankedStat, _ := gonhl.ConvertTeamStatsToTeamRanks(teams[0].TeamStats[0].Splits[1].Stat)
fmt.Println(rankedStat.Wins != "")
// Output:
// New Jersey Devils
// statsSingleSeason
// /api/v1/teams/1/roster
// true
// true
}
// Example of retrieving a single team.
// Gets detailed roster, scheduling, and stats (values and rank) for the New York Islanders.
func ExampleClient_GetTeam() {
//TODO want to validate schedule params
client := gonhl.NewClient()
teamsParams := gonhl.NewTeamsParams().
ShowDetailedRoster().
ShowScheduleNext().
ShowSchedulePrev().
ShowTeamStats().
SetTeamIds(2)
team, _ := client.GetTeam(teamsParams)
fmt.Println(team.Name)
// Output: New York Islanders
}
func ExampleClient_GetTeamStats() {
client := gonhl.NewClient()
teamStats, _ := client.GetTeamStats(1)
fmt.Println(teamStats[0].Splits[0].Team.ID)
fmt.Println(teamStats[0].Type.DisplayName)
stats, _ := teamStats[0].Splits[0].Stat.(gonhl.TeamStats)
fmt.Println(stats.Wins > 0)
fmt.Println(teamStats[1].Type.DisplayName)
ranks, _ := teamStats[1].Splits[0].Stat.(gonhl.TeamStatRanks)
fmt.Println(ranks.Wins != "")
// Output:
// 1
// statsSingleSeason
// true
// regularSeasonStatRankings
// true
}
// Example of retrieving a prospect.
// Prospect information for Connor McDavid.
func ExampleClient_GetProspect() {
client := gonhl.NewClient()
prospect, _ := client.GetProspect(54223)
fmt.Println(prospect.FullName)
// Output: Connor Mcdavid
}
// Example of retrieving a schedule.
// Be careful of dates as they may not be the same timezone.
func ExampleClient_GetSchedule() {
client := gonhl.NewClient()
date, _ := time.Parse("2006-01-02", "2018-12-04")
scheduleParams := gonhl.NewScheduleParams().
SetDate(date).ShowTicketRetailers()
schedule, _ := client.GetSchedule(scheduleParams)
fmt.Println(schedule.Dates[0].Games[0].GameDate.Format("2006-01-02"))
fmt.Println(schedule.Dates[0].Date.Format("2006-01-02"))
fmt.Println(schedule.Dates[0].Games[0].Venue.Name)
fmt.Println(schedule.Dates[0].Games[0].Teams.Home.Score)
fmt.Println(schedule.Dates[0].Games[0].Teams.Away.Score)
fmt.Println(len(schedule.Dates[0].Games[0].Tickets))
fmt.Println(len(schedule.Dates[0].Games[0].Broadcasts))
// Output:
// 2018-12-05
// 2018-12-04
// BB&T Center
// 5
// Boston Bruins
// 23
// 0
}
// Example of retrieving only the live data of a game.
func ExampleClient_GetGameLiveData() {
client := gonhl.NewClient()
feed, _ := client.GetGameLiveData(2018020514)
fmt.Println(feed.Boxscore.Teams.Home.Team.Name)
fmt.Println(feed.Boxscore.Teams.Home.OnIcePlus[0].PlayerID)
fmt.Println(feed.Plays.CurrentPlay.About.DateTime.String())
// Output:
// Montréal Canadiens
// 8470642
// 2018-12-18 03:00:57 +0000 UTC
}
func ExampleClient_GetGameLiveFeed() {
client := gonhl.NewClient()
feed, _ := client.GetGameLiveFeed(2018020514)
fmt.Println(feed.LiveData.Boxscore.Teams.Home.Team.Name)
fmt.Println(feed.LiveData.Boxscore.Teams.Home.OnIcePlus[0].PlayerID)
// Output:
// Montréal Canadiens
// 8470642
}
func ExampleClient_GetGamePlaysAndPlayers() {
client := gonhl.NewClient()
location, _ := time.LoadLocation("America/Toronto")
date := time.Date(2018, 10, 27, 16, 0, 0, 0, location)
liveData, _ := client.GetGameLiveDataDiff(2018020150, date)
fmt.Println(liveData.Plays.AllPlays[15].Result.Description)
fmt.Println(liveData.Plays.AllPlays[15].Result.Event)
fmt.Println(liveData.Plays.AllPlays[15].Result.EventCode)
fmt.Println(liveData.Plays.AllPlays[15].Result.EventTypeID)
fmt.Println(liveData.Boxscore.Teams.Home.OnIcePlus[0].PlayerID)
fmt.Println(liveData.Boxscore.Teams.Home.Players["ID8476887"].Person.FullName)
// Output:
// Zack Kassian hit Anthony Bitetto
// Hit
// NSH55
// HIT
// 8474056
// Filip Forsberg
}