forked from nicklaw5/helix
-
Notifications
You must be signed in to change notification settings - Fork 1
/
subscriptions.go
96 lines (82 loc) · 3.23 KB
/
subscriptions.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
package helix
type Subscription struct {
BroadcasterID string `json:"broadcaster_id"`
BroadcasterLogin string `json:"broadcaster_login"`
BroadcasterName string `json:"broadcaster_name"`
IsGift bool `json:"is_gift"`
GifterID string `json:"gifter_id"`
GifterLogin string `json:"gifter_login"`
GifterName string `json:"gifter_name"`
Tier string `json:"tier"`
PlanName string `json:"plan_name"`
UserID string `json:"user_id"`
UserName string `json:"user_name"`
UserLogin string `json:"user_login"`
}
type UserSubscription struct {
BroadcasterID string `json:"broadcaster_id"`
BroadcasterLogin string `json:"broadcaster_login"`
BroadcasterName string `json:"broadcaster_name"`
IsGift bool `json:"is_gift"`
GifterLogin string `json:"gifter_login"`
GifterName string `json:"gifter_name"`
Tier string `json:"tier"`
}
type ManySubscriptions struct {
Subscriptions []Subscription `json:"data"`
Pagination Pagination `json:"pagination"`
Total int `json:"total"`
Points int `json:"points"` // Each Tier 1 is worth 1, Tier 2 is worth 2, and Tier 3 is worth 6
}
type ManyUserSubscriptions struct {
UserSubscriptions []UserSubscription `json:"data"`
}
type SubscriptionsResponse struct {
ResponseCommon
Data ManySubscriptions
}
type UserSubscriptionResponse struct {
ResponseCommon
Data ManyUserSubscriptions
}
type SubscriptionsParams struct {
BroadcasterID string `query:"broadcaster_id"` // Limit 1
UserID []string `query:"user_id"` // Limit 100
After string `query:"after"`
Before string `query:"before"`
First int `query:"first,20"` // Limit 100
}
type UserSubscriptionsParams struct {
BroadcasterID string `query:"broadcaster_id"`
UserID string `query:"user_id"`
}
// GetSubscriptions gets subscriptions about one Twitch broadcaster.
// Broadcasters can only request their own subscriptions.
//
// Required scope: channel:read:subscriptions
func (c *Client) GetSubscriptions(params *SubscriptionsParams) (*SubscriptionsResponse, error) {
resp, err := c.get("/subscriptions", &ManySubscriptions{}, params)
if err != nil {
return nil, err
}
subscriptions := &SubscriptionsResponse{}
resp.HydrateResponseCommon(&subscriptions.ResponseCommon)
subscriptions.Data.Subscriptions = resp.Data.(*ManySubscriptions).Subscriptions
subscriptions.Data.Pagination = resp.Data.(*ManySubscriptions).Pagination
subscriptions.Data.Total = resp.Data.(*ManySubscriptions).Total
subscriptions.Data.Points = resp.Data.(*ManySubscriptions).Points
return subscriptions, nil
}
// CheckUserSubscription Check if a specific user is subscribed to a specific channel
//
// Required scope: user:read:subscriptions
func (c *Client) CheckUserSubscription(params *UserSubscriptionsParams) (*UserSubscriptionResponse, error) {
resp, err := c.get("/subscriptions/user", &ManyUserSubscriptions{}, params)
if err != nil {
return nil, err
}
subscriptions := &UserSubscriptionResponse{}
resp.HydrateResponseCommon(&subscriptions.ResponseCommon)
subscriptions.Data.UserSubscriptions = resp.Data.(*ManyUserSubscriptions).UserSubscriptions
return subscriptions, nil
}