-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.go
35 lines (29 loc) · 888 Bytes
/
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
package nagato
import (
"context"
"net/http"
)
// GetUserInfo to get user info.
//
// Only `@me` in username param works for now.
//
// Need oauth2.
func (c *Client) GetUserInfo(username string, fields ...UserField) (*User, int, error) {
return c.GetUserInfoWithContext(context.Background(), username, fields...)
}
// GetUserInfoWithContext to get user info with context.
//
// Only `@me` in username param works for now.
//
// Need oauth2.
func (c *Client) GetUserInfoWithContext(ctx context.Context, username string, fields ...UserField) (*User, int, error) {
u := usernameParam{Username: username}
if err := c.validate(&u); err != nil {
return nil, http.StatusBadRequest, err
}
user, code, err := c.mal.GetUserInfoWithContext(ctx, u.Username, c.userFieldsToStrs(fields...)...)
if err != nil {
return nil, code, err
}
return c.userToUser(user), http.StatusOK, nil
}