Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass options and support new fields for user info #13

Merged
merged 1 commit into from
May 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion mal/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@ type UserService struct {
type User struct {
ID int64 `json:"id"`
Name string `json:"name"`
Picture string `json:"picture"`
Gender string `json:"gender"`
Birthday string `json:"birthday"`
Location string `json:"location"`
Picture string `json:"picture"`
JoinedAt time.Time `json:"joined_at"`
AnimeStatistics AnimeStatistics `json:"anime_statistics"`
TimeZone string `json:"time_zone"`
IsSupporter bool `json:"is_supporter"`
}

// AnimeStatistics about the user.
Expand Down Expand Up @@ -58,6 +61,11 @@ func (s *UserService) MyInfo(ctx context.Context, options ...MyInfoOption) (*Use
if err != nil {
return nil, nil, err
}
q := req.URL.Query()
for _, o := range options {
o.myInfoApply(&q)
}
req.URL.RawQuery = q.Encode()

u := new(User)
resp, err := s.client.Do(ctx, req, u)
Expand Down
7 changes: 6 additions & 1 deletion mal/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@ func TestUserServiceMyInfo(t *testing.T) {

mux.HandleFunc("/users/@me", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
testURLValues(t, r, urlValues{
"fields": "time_zone,is_supporter",
})
fmt.Fprint(w, `{"id":1}`)
})

ctx := context.Background()
u, _, err := client.User.MyInfo(ctx)
u, _, err := client.User.MyInfo(ctx,
Fields{"time_zone", "is_supporter"},
)
if err != nil {
t.Errorf("User.MyInfo returned error: %v", err)
}
Expand Down