-
Notifications
You must be signed in to change notification settings - Fork 3
/
account.go
188 lines (168 loc) · 4.94 KB
/
account.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
package lichess
import (
"bytes"
"encoding/json"
)
type Profile struct {
Bio string `json:"bio"`
Country string `json:"country"`
FirstName string `json:"firstName"`
LastName string `json:"lastName"`
Links string `json:"links"`
Location string `json:"location"`
FideRating int `json:"fideRating"`
UscfRating int `json:"uscfRating"`
EcfRating int `json:"ecfRating"`
}
type Count struct {
AI int `json:"ai"`
All int `json:"all"`
Bookmark int `json:"bookmark"`
Draw int `json:"draw"`
Import int `json:"import"`
Loss int `json:"loss"`
LossH int `json:"lossH"`
Me int `json:"me"`
Playing int `json:"playing"`
Rated int `json:"rated"`
Win int `json:"win"`
WinH int `json:"winH"`
}
type PrefsStats struct {
Games int `json:"games"`
Prog int `json:"prog"`
Rating int `json:"rating"`
RD int `json:"rd"`
}
type Perfs struct {
Blitz PrefsStats `json:"blitz"`
Bullet PrefsStats `json:"bullet"`
Chess960 PrefsStats `json:"chess960"`
Puzzle PrefsStats `json:"puzzle"`
}
type PlayTime struct {
Total int `json:"total"`
Tv int `json:"tv"`
}
type User struct {
ID string `json:"id"`
Username string `json:"username"`
Title string `json:"title"`
Online bool `json:"online"`
Playing string `json:"playing"`
CreatedAt int `json:"createdAt"`
SeenAt int `json:"seenAt"`
Profile Profile `json:"profile"`
NbFollowers int `json:"nbFollowers"`
NbFollowing int `json:"nbFollowing"`
CompletionRate int `json:"completionRate"`
Language string `json:"language"`
Count Count `json:"count"`
Perfs Perfs `json:"perfs"`
Patron bool `json:"patron"`
Disabled bool `json:"disabled"`
Engine bool `json:"engine"`
Booster bool `json:"booster"`
PlayTime PlayTime `json:"playTime"`
}
type Email struct {
Email string `json:"email"`
}
type ProfilePrefs struct {
Dark bool `json:"dark"`
Transp bool `json:"transp"`
BackgroundImage string `json:"bgImg"`
Is3D bool `json:"is3d"`
Theme string `json:"theme"`
PieceSet string `json:"pieceSet"`
Theme3D string `json:"theme3d"`
PieceSet3D string `json:"pieceSet3d"`
SoundSet string `json:"soundSet"`
BlindFold int `json:"blindfold"`
AutoQueen int `json:"autoQueen"`
AutoThreefold int `json:"autoThreefold"`
Takeback int `json:"takeback"`
ClockTenths int `json:"clockTenths"`
ClockBar bool `json:"clockBar"`
ClockSound bool `json:"clockSound"`
Premove bool `json:"premove"`
Animation int `json:"animation"`
Captured bool `json:"captured"`
Follow bool `json:"follow"`
Highlight bool `json:"highlight"`
Destination bool `json:"destination"`
Coords int `json:"coords"`
Replay int `json:"replay"`
Callenge int `json:"callenge"`
Message int `json:"message"`
CoordColor int `json:"coordColor"`
SubmitMove int `json:"submitMove"`
ConfirmResign int `json:"confirmResign"`
InsightShare int `json:"insightShare"`
KeyboardMove int `json:"keyboardMove"`
Zen int `json:"zen"`
MoveEvent int `json:"moveEvent"`
}
type Preferences struct {
Prefs ProfilePrefs `json:"prefs"`
}
type KidModeStatus struct {
Kid bool `json:"kid"`
}
type Ok struct {
Ok bool `json:"ok"`
}
// Will return profile information
func (c *Client) GetProfile() (*User, error) {
req, err := c.newRequest("GET", "/api/account", nil)
user := new(User)
_, err = c.do(req, &user)
if err != nil {
return nil, err
}
return user, err
}
// Will return the email for the account
func (c *Client) GetEmail() (*Email, error) {
req, err := c.newRequest("GET", "/api/account/email", nil)
email := new(Email)
_, err = c.do(req, &email)
if err != nil {
return nil, err
}
return email, err
}
// Will return preferences of the account
func (c *Client) GetPreferences() (*Preferences, error) {
req, err := c.newRequest("GET", "/api/account/preferences", nil)
pref := new(Preferences)
_, err = c.do(req, &pref)
if err != nil {
return nil, err
}
return pref, err
}
// Will return the kid mode status of the account
func (c *Client) GetKidModeStatus() (*KidModeStatus, error) {
req, err := c.newRequest("GET", "/api/account/kid", nil)
kid := new(KidModeStatus)
_, err = c.do(req, &kid)
if err != nil {
return nil, err
}
return kid, err
}
// Set Kid mode on account
func (c *Client) SetKidModeStatus(KidStaus bool) (*Ok, error) {
kidStaus := map[string]bool{
"kid": KidStaus,
}
jsonPayload, _ := json.Marshal(kidStaus)
req, err := c.newRequest("POST", "/api/account/kid", bytes.NewBuffer(jsonPayload))
okStatus := new(Ok)
_, err = c.do(req, &okStatus)
if err != nil {
return nil, err
}
return okStatus, err
}