-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubscriptions.go
92 lines (76 loc) · 2.16 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
package twch
import (
"fmt"
)
type Subscriptions struct {
client *Client
}
type listSubscription struct {
Subscriptions []Subscription `json:"subscriptions,omitempty"`
*listLinks
*listTotal
}
type Subscription struct {
ID *string `json:"_id,omitempty"`
User *User `json:"user,omitempty"`
Channel *Channel `json:"channel,omitempty"`
CreatedAt *string `json:"created_at,omitempty"`
}
type SubscriptionOptions struct {
Direction string `url:"direction,omitempty"`
ListOptions
}
// GetChannelSubscriptions returns a list of subscriptions for the given channel,
// ordered by creation date.
// Requires the `channel_subscriptions` authentication scope.
func (s *Subscriptions) GetChannelSubscriptions(channel string, opts *SubscriptionOptions) (sub []Subscription, resp *Response, err error) {
url := fmt.Sprintf("channels/%s/subscriptions", channel)
url, err = appendOptions(url, opts)
if err != nil {
return
}
req, err := s.client.NewRequest("GET", url)
if err != nil {
return
}
r := new(listSubscription)
resp, err = s.client.Do(req, r)
if err != nil {
return
}
sub = r.Subscriptions
return
}
// UserSubscribed returns a subscription if the user is subscribed to
// the given channel.
// Requires the `channel_check_subscription` authentication scope for
// the given channel.
func (s *Subscriptions) GetUserSubscribed(channel, user string) (sub *Subscription, resp *Response, err error) {
url := fmt.Sprintf("channels/%s/subscriptions/%s", channel, user)
req, err := s.client.NewRequest("GET", url)
if err != nil {
return
}
sub = new(Subscription)
resp, err = s.client.Do(req, sub)
if err != nil {
return
}
return
}
// ChannelSubscribed returns a subscription with a channel that the user
// subscribes to.
// Requires the `user_subscriptions` authentication scope for the given user.
func (s *Subscriptions) GetSubscribedChannel(user, channel string) (sub *Subscription, resp *Response, err error) {
url := fmt.Sprintf("users/%s/subscriptions/%s", user, channel)
req, err := s.client.NewRequest("GET", url)
if err != nil {
return
}
sub = new(Subscription)
resp, err = s.client.Do(req, sub)
if err != nil {
return
}
return
}