-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser.go
55 lines (47 loc) · 1.35 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
package suzuri
import (
"context"
"strconv"
)
// User is a SUZURI user account.
type User struct {
ID int `json:"id"`
Name string `json:"name"`
DisplayName string `json:"displayName"`
AvatarURL string `json:"avatarUrl"`
Identities []UserIdentity `json:"identities"`
Profile UserProfile `json:"profile"`
}
// UserIdentity is information about social account connected with a User.
type UserIdentity struct {
ID int `json:"id"`
Provider string `json:"provider"`
UID string `json:"uid"`
Nickname string `json:"nickname"`
URL string `json:"url"`
}
// UserProfile is a profile of User.
type UserProfile struct {
ID int `json:"id"`
URL string `json:"url"`
Body string `json:"body"`
HeaderURL string `json:"headerUrl"`
}
// userResponse is a response data structure when API returns a User.
type userResponse struct {
User User `json:"user"`
}
// GetUser gets details about an existing user.
func (c *Client) GetUser(ctx context.Context, userID int) (*User, error) {
endpoint := "/users/" + strconv.Itoa(userID)
resp, err := c.get(ctx, endpoint, nil)
if err != nil {
return nil, err
}
// TODO: status chack and error handling
var userResp userResponse
if err := decodeJSON(resp, &userResp); err != nil {
return nil, err
}
return &userResp.User, nil
}