forked from nicklaw5/helix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusers.go
124 lines (105 loc) · 3.36 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
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 gets information about one or more specified Twitch users.
// Users are identified by optional user IDs and/or login name. If neither
// a user ID nor a login name is specified, the user is looked up by Bearer token.
//
// Optional scope: user:read:email
func (c *Client) GetUsers(params *UsersParams) (*UsersResponse, error) {
resp, err := c.get("/users", &ManyUsers{}, params)
if err != nil {
return nil, err
}
users := &UsersResponse{}
resp.HydrateResponseCommon(&users.ResponseCommon)
users.Data.Users = resp.Data.(*ManyUsers).Users
return users, nil
}
// UpdateUserParams ...
type UpdateUserParams 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(params *UpdateUserParams) (*UsersResponse, error) {
resp, err := c.put("/users", &ManyUsers{}, params)
if err != nil {
return nil, err
}
users := &UsersResponse{}
resp.HydrateResponseCommon(&users.ResponseCommon)
users.Data.Users = resp.Data.(*ManyUsers).Users
return users, nil
}
// UserFollow ...
type UserFollow struct {
FromID string `json:"from_id"`
FromLogin string `json:"from_login"`
FromName string `json:"from_name"`
ToID string `json:"to_id"`
ToName string `json:"to_name"`
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"`
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{}
resp.HydrateResponseCommon(&users.ResponseCommon)
users.Data.Total = resp.Data.(*ManyFollows).Total
users.Data.Follows = resp.Data.(*ManyFollows).Follows
users.Data.Pagination = resp.Data.(*ManyFollows).Pagination
return users, nil
}