-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.go
129 lines (113 loc) · 4.56 KB
/
player.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
package chesscompubapi
import (
"fmt"
)
type PlayerProfile struct {
URL string `json:"url"`
Username string `json:"username"`
PlayerId int `json:"player_id"`
Title *string `json:"title"`
Status string `json:"status"`
Name string `json:"name"`
Avatar string `json:"avatar"`
Location string `json:"location"`
CountryCode StringFromPathSuffix `json:"country"`
Joined UnixSecondsTimestamp `json:"joined"`
LastOnline UnixSecondsTimestamp `json:"last_online"`
Followers int `json:"followers"`
IsStreamer bool `json:"is_streamer"`
Verified bool `json:"verified"`
League string `json:"league"`
TwitchURL string `json:"twitch_url"`
FIDE int `json:"fide"`
}
type PlayerClub struct {
URL string `json:"url"`
Name string `json:"name"`
Joined UnixSecondsTimestamp `json:"joined"`
LastActivity UnixSecondsTimestamp `json:"last_activity"`
Icon string `json:"icon"`
ID StringFromPathSuffix `json:"@id"`
}
type PlayerStats struct {
ChessDaily *PlayerGameTypeStats `json:"chess_daily"`
Chess960Daily *PlayerGameTypeStats `json:"chess960_daily"`
ChessBlitz *PlayerGameTypeStats `json:"chess_blitz"`
ChessBullet *PlayerGameTypeStats `json:"chess_bullet"`
ChessRapid *PlayerGameTypeStats `json:"chess_rapid"`
Tactics *PlayerHighestLowestStats `json:"tactics"`
Lessons *PlayerHighestLowestStats `json:"lessons"`
PuzzleRush *PlayerPuzzleRushStats `json:"puzzle_rush"`
FIDE int `json:"fide"`
}
type PlayerGameTypeStats struct {
Last LastPlayerGameTypeStats `json:"last"`
Best *BestPlayerGameTypeStats `json:"best"`
Record RecordPlayerGameTypeStats `json:"record"`
Tournament TournamentPlayerGameTypeStats `json:"tournament"`
}
type LastPlayerGameTypeStats struct {
Date UnixSecondsTimestamp `json:"date"`
Rating int `json:"rating"`
RD int `json:"rd"`
}
type BestPlayerGameTypeStats struct {
Date UnixSecondsTimestamp `json:"date"`
Rating int `json:"rating"`
Game string `json:"game"`
}
type RecordPlayerGameTypeStats struct {
Win int `json:"win"`
Loss int `json:"loss"`
Draw int `json:"draw"`
TimePerMove *DurationInSeconds `json:"time_per_move"`
TimeoutPercent *float64 `json:"timeout_percent"`
}
type TournamentPlayerGameTypeStats struct {
Count int `json:"count"`
Withdraw int `json:"withdraw"`
Points int `json:"points"`
HighestFinish int `json:"highest_finish"`
}
type PlayerHighestLowestStats struct {
Highest DateRating `json:"highest"`
Lowest DateRating `json:"lowest"`
}
type DateRating struct {
Date UnixSecondsTimestamp `json:"date"`
Rating int `json:"rating"`
}
type PlayerPuzzleRushStats struct {
Daily *TotalAttemptsScore `json:"daily"`
Best TotalAttemptsScore `json:"best"`
}
type TotalAttemptsScore struct {
TotalAttempts int `json:"total_attempts"`
Score int `json:"score"`
}
// GetPlayerProfile gets the profile of a player.
// Details about the endpoint can be found at https://www.chess.com/news/view/published-data-api#pubapi-endpoint-player.
func (c *Client) GetPlayerProfile(username string) (PlayerProfile, error) {
const urlTemplate = "player/%s"
profile := PlayerProfile{}
err := c.getInto(fmt.Sprintf(urlTemplate, username), &profile)
return profile, err
}
// ListPlayerClubs lists the clubs that a player is member of.
// Details about the endpoint can be found at https://www.chess.com/news/view/published-data-api#pubapi-endpoint-player-clubs.
func (c *Client) ListPlayerClubs(username string) ([]PlayerClub, error) {
const urlTemplate = "player/%s/clubs"
clubs := &struct {
Clubs []PlayerClub `json:"clubs"`
}{}
err := c.getInto(fmt.Sprintf(urlTemplate, username), clubs)
return clubs.Clubs, err
}
// GetPlayerStats gets the profile of a player.
// Details about the endpoint can be found at https://www.chess.com/news/view/published-data-api#pubapi-endpoint-player-stats.
func (c *Client) GetPlayerStats(username string) (PlayerStats, error) {
const urlTemplate = "player/%s/stats"
stats := PlayerStats{}
err := c.getInto(fmt.Sprintf(urlTemplate, username), &stats)
return stats, err
}