-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_subscribed_channels.go
85 lines (69 loc) · 2.25 KB
/
get_subscribed_channels.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
package channels
import (
"context"
"encoding/json"
"net/http"
"github.com./wakumaku/go-zulip"
)
type GetSubscribedChannelsResponse struct {
zulip.APIResponseBase
getSubscribedChannelsResponseData
}
type getSubscribedChannelsResponseData struct {
Subscriptions []struct {
AudibleNotifications bool `json:"audible_notifications"`
Color string `json:"color"`
CreatorID int `json:"creator_id"`
Description string `json:"description"`
DesktopNotifications bool `json:"desktop_notifications"`
InviteOnly bool `json:"invite_only"`
IsArchived bool `json:"is_archived"`
IsMuted bool `json:"is_muted"`
Name string `json:"name"`
PinToTop bool `json:"pin_to_top"`
PushNotifications bool `json:"push_notifications"`
StreamID int `json:"stream_id"`
Subscribers []int `json:"subscribers"`
} `json:"subscriptions"`
}
func (g *GetSubscribedChannelsResponse) UnmarshalJSON(b []byte) error {
if err := json.Unmarshal(b, &g.APIResponseBase); err != nil {
return err
}
if err := json.Unmarshal(b, &g.getSubscribedChannelsResponseData); err != nil {
return err
}
return nil
}
type getSubscribedChannelsOptions struct {
includeSubscribers struct {
fieldName string
value *bool
}
}
type GetSubscribedChannelsOption func(*getSubscribedChannelsOptions)
func IncludeSubscribersList(includeSubscribers bool) GetSubscribedChannelsOption {
return func(o *getSubscribedChannelsOptions) {
o.includeSubscribers.fieldName = "include_subscribers"
o.includeSubscribers.value = &includeSubscribers
}
}
func (svc *Service) GetSubscribedChannels(ctx context.Context, options ...GetSubscribedChannelsOption) (*GetSubscribedChannelsResponse, error) {
const (
method = http.MethodGet
path = "/api/v1/users/me/subscriptions"
)
msg := map[string]any{}
opts := getSubscribedChannelsOptions{}
for _, opt := range options {
opt(&opts)
}
if opts.includeSubscribers.value != nil {
msg[opts.includeSubscribers.fieldName] = *opts.includeSubscribers.value
}
resp := GetSubscribedChannelsResponse{}
if err := svc.client.DoRequest(ctx, method, path, msg, &resp); err != nil {
return nil, err
}
return &resp, nil
}