-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathfollow.go
More file actions
65 lines (52 loc) · 1.71 KB
/
Copy pathfollow.go
File metadata and controls
65 lines (52 loc) · 1.71 KB
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
package twitch
import (
"fmt"
"net/url"
"time"
)
type Follow struct {
CreatedAt time.Time `json:"created_at"`
Id string `json:"_id"`
User User `json:"user"`
Notifications bool `json:"notifications"`
}
type FollowResponse struct {
Total int64 `json:"_total"`
Follows []Follow `json:"follows"`
}
func (client *TwitchClient) GetChannelFollows(channel string, options *RequestOptions) FollowResponse {
res := FollowResponse{}
client.getRequest(fmt.Sprintf("/channels/%s/follows", channel), options, &res)
return res
}
type helixFollowResponse struct {
Total int64 `json:"total"`
Follows []helixFollow `json:"data"`
Pagination map[string]string `json:"pagination"`
}
type helixFollow struct {
FromID string `json:"from_id"`
FromName string `json:"from_name"`
ToID string `json:"to_id"`
ToName string `json:"to_name"`
FollowedAt time.Time `json:"followed_at"`
}
/*
GetFollowersForID requests follower information for a user/channel ID.
https://dev.twitch.tv/docs/api/reference/#get-users-follows
Follower data is sorted by Twitch: most recent follower first.
A pagination cursor may be available in yourResponse.Pagination["cursor"]. This can be supplied in the options.Extra struct with the key "after" on subsequent calls.
*/
func (client *TwitchClient) GetFollowersForID(userID string, options *RequestOptions) (helixFollowResponse, error) {
if options == nil {
options = &RequestOptions{}
}
options.Version = "helix"
if options.Extra == nil {
options.Extra = &url.Values{}
}
options.Extra.Add("to_id", userID)
res := helixFollowResponse{}
err := client.getRequest("/users/follows", options, &res)
return res, err
}