-
Notifications
You must be signed in to change notification settings - Fork 2
/
user.go
103 lines (90 loc) · 3.33 KB
/
user.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
package wanikaniapi
import (
"time"
)
//////////////////////////////////////////////////////////////////////////////
//
//
//
// Exported functions
//
//
//
//////////////////////////////////////////////////////////////////////////////
// UserGet returns a summary of user information.
func (c *Client) UserGet(params *UserGetParams) (*User, error) {
obj := &User{}
err := c.request("GET", "/v2/user", params, nil, obj)
return obj, err
}
// UserUpdate returns an updated summary of user information.
func (c *Client) UserUpdate(params *UserUpdateParams) (*User, error) {
wrapper := &userUpdateParamsWrapper{Params: params.Params, User: params}
obj := &User{}
err := c.request("PUT", "/v2/user", params, wrapper, obj)
return obj, err
}
//////////////////////////////////////////////////////////////////////////////
//
//
//
// Exported constants/types
//
//
//
//////////////////////////////////////////////////////////////////////////////
// User returns basic information for the user making the API request,
// identified by their API token.
type User struct {
Object
Data *UserData `json:"data"`
}
// UserData contains core data of User.
type UserData struct {
CurrentVacationStartedAt *time.Time `json:"current_vacation_started_at"`
WKID string `json:"id"`
Level int `json:"level"`
Preferences *UserPreferences `json:"preferences"`
ProfileURL string `json:"profile_url"`
StartedAt time.Time `json:"started_at"`
Subscription *UserSubscription `json:"subscription"`
Username string `json:"username"`
}
// UserGetParams are parameters for UserGet.
type UserGetParams struct {
Params
}
// UserPreferences are preferences for a user.
type UserPreferences struct {
DefaultVoiceActorID WKID `json:"default_voice_actor_id"`
LessonsAutoplayAudio bool `json:"lessons_autoplay_audio"`
LessonsBatchSize int `json:"lessons_batch_size"`
LessonsPresentationOrder string `json:"lessons_presentation_order"`
ReviewsAutoplayAudio bool `json:"reviews_autoplay_audio"`
ReviewsDisplaySRSIndicator bool `json:"reviews_display_srs_indicator"`
}
// UserSubscription represents a subscription for a user.
type UserSubscription struct {
Active bool `json:"active"`
MaxLevelGranted int `json:"max_level_granted"`
PeriodEndsAt *time.Time `json:"period_ends_at"`
Type string `json:"type"`
}
// UserUpdateParams are parameters for UserUpdate.
type UserUpdateParams struct {
Params
Preferences *UserUpdatePreferencesParams `json:"preferences,omitempty"`
}
// UserUpdatePreferencesParams are update parameters for user preferences.
type UserUpdatePreferencesParams struct {
DefaultVoiceActorID *WKID `json:"default_voice_actor_id,omitempty"`
LessonsAutoplayAudio *bool `json:"lessons_autoplay_audio,omitempty"`
LessonsBatchSize *int `json:"lessons_batch_size,omitempty"`
LessonsPresentationOrder *string `json:"lessons_presentation_order,omitempty"`
ReviewsAutoplayAudio *bool `json:"reviews_autoplay_audio,omitempty"`
ReviewsDisplaySRSIndicator *bool `json:"reviews_display_srs_indicator,omitempty"`
}
type userUpdateParamsWrapper struct {
Params
User *UserUpdateParams `json:"user"`
}