forked from bearyinnovative/bearychat-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.go
89 lines (75 loc) · 2.1 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
package openapi
import (
"context"
"fmt"
"net/http"
)
type UserType string
type UserRole string
type UserAvatar struct {
Small string `json:"small,omitempty"`
Medium string `json:"medium,omitempty"`
Large string `json:"large,omitempty"`
}
type UserProfile struct {
Bio string `json:"bio,omitempty"`
Position string `json:"position,omitempty"`
Skype string `json:"sykpe,omitempty"`
}
type User struct {
ID string `json:"id,omitempty"`
TeamID string `json:"team_id,omitempty"`
Email string `json:"email,omitempty"`
Name string `json:"name,omitempty"`
FullName string `json:"full_name,omitempty"`
Type UserType `json:"type,omitempty"`
Role UserRole `json:"role,omitempty"`
Avatars UserAvatar `json:"avatars,omitempty"`
Profile UserProfile `json:"profile,omitempty"`
Inactive bool `json:"inactive,omitempty"`
Created Time `json:"created,omitempty"`
}
type UserService service
type UserInfoOptions struct {
UserID string
}
// Info implements `GET /user.info`
func (u *UserService) Info(ctx context.Context, opt *UserInfoOptions) (*User, *http.Response, error) {
endpoint := fmt.Sprintf("user.info?user_id=%s", opt.UserID)
req, err := u.client.newRequest("GET", endpoint, nil)
if err != nil {
return nil, nil, err
}
var user User
resp, err := u.client.do(ctx, req, &user)
if err != nil {
return nil, resp, err
}
return &user, resp, nil
}
// List implements `GET /user.list`
func (u *UserService) List(ctx context.Context) ([]*User, *http.Response, error) {
req, err := u.client.newRequest("GET", "user.list", nil)
if err != nil {
return nil, nil, err
}
var users []*User
resp, err := u.client.do(ctx, req, &users)
if err != nil {
return nil, resp, err
}
return users, resp, nil
}
// Me implements `GET /user.me`
func (u *UserService) Me(ctx context.Context) (*User, *http.Response, error) {
req, err := u.client.newRequest("GET", "user.me", nil)
if err != nil {
return nil, nil, err
}
var user User
resp, err := u.client.do(ctx, req, &user)
if err != nil {
return nil, resp, err
}
return &user, resp, nil
}