forked from nicklaw5/helix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusers.go
133 lines (113 loc) · 3.4 KB
/
users.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package helix
import "time"
// User ...
type User struct {
ID string `json:"id"`
Login string `json:"login"`
DisplayName string `json:"display_name"`
Type string `json:"type"`
BroadcasterType string `json:"broadcaster_type"`
Description string `json:"description"`
ProfileImageURL string `json:"profile_image_url"`
OfflineImageURL string `json:"offline_image_url"`
ViewCount int `json:"view_count"`
Email string `json:"email"`
}
// ManyUsers ...
type ManyUsers struct {
Users []User `json:"data"`
}
// UsersResponse ...
type UsersResponse struct {
ResponseCommon
Data ManyUsers
}
// UsersParams ...
type UsersParams struct {
IDs []string `query:"id"` // Limit 100
Logins []string `query:"login"` // Limit 100
}
// GetUsers ...
func (c *Client) GetUsers(params *UsersParams) (*UsersResponse, error) {
resp, err := c.get("/users", &ManyUsers{}, params)
if err != nil {
return nil, err
}
users := &UsersResponse{}
users.StatusCode = resp.StatusCode
users.Header = resp.Header
users.Error = resp.Error
users.ErrorStatus = resp.ErrorStatus
users.ErrorMessage = resp.ErrorMessage
users.Data.Users = resp.Data.(*ManyUsers).Users
return users, nil
}
type updateUserRequestData struct {
Description string `query:"description"`
}
// UpdateUser updates the description of a user specified
// by a Bearer token.
//
// Required scope: user:edit
func (c *Client) UpdateUser(description string) (*UsersResponse, error) {
data := &updateUserRequestData{
Description: description,
}
resp, err := c.put("/users", &ManyUsers{}, data)
if err != nil {
return nil, err
}
users := &UsersResponse{}
users.StatusCode = resp.StatusCode
users.Header = resp.Header
users.Error = resp.Error
users.ErrorStatus = resp.ErrorStatus
users.ErrorMessage = resp.ErrorMessage
users.Data.Users = resp.Data.(*ManyUsers).Users
return users, nil
}
// UserFollow ...
type UserFollow struct {
FromID string `json:"from_id"`
ToID string `json:"to_id"`
FollowedAt time.Time `json:"followed_at"`
}
// ManyFollows ...
type ManyFollows struct {
Total int `json:"total"`
Follows []UserFollow `json:"data"`
Pagination Pagination `json:"pagination"`
}
// UsersFollowsResponse ...
type UsersFollowsResponse struct {
ResponseCommon
Data ManyFollows
}
// UsersFollowsParams ...
type UsersFollowsParams struct {
After string `query:"after"`
Before string `query:"before"`
First int `query:"first,20"` // Limit 100
FromID string `query:"from_id"`
ToID string `query:"to_id"`
}
// GetUsersFollows gets information on follow relationships between two Twitch users.
// Information returned is sorted in order, most recent follow first. This can return
// information like “who is lirik following,” “who is following lirik,” or “is user X
// following user Y.”
func (c *Client) GetUsersFollows(params *UsersFollowsParams) (*UsersFollowsResponse, error) {
resp, err := c.get("/users/follows", &ManyFollows{}, params)
if err != nil {
return nil, err
}
users := &UsersFollowsResponse{}
users.StatusCode = resp.StatusCode
users.Header = resp.Header
users.Error = resp.Error
users.ErrorStatus = resp.ErrorStatus
users.ErrorMessage = resp.ErrorMessage
users.Data.Total = resp.Data.(*ManyFollows).Total
users.Data.Follows = resp.Data.(*ManyFollows).Follows
users.Data.Pagination = resp.Data.(*ManyFollows).Pagination
return users, nil
}