forked from nicklaw5/helix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchannels.go
114 lines (95 loc) · 3.67 KB
/
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
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
package helix
// SearchChannelsParams is parameters for SearchChannels
type SearchChannelsParams struct {
Channel string `query:"query"`
After string `query:"after"`
First int `query:"first,20"` // Limit 100
LiveOnly bool `query:"live_only"`
}
// ManySearchChannels is the response data from SearchChannels
type ManySearchChannels struct {
Channels []Channel `json:"data"`
Pagination Pagination `json:"pagination"`
}
// Channel describes a channel from SearchChannel
type Channel struct {
ID string `json:"id"`
GameID string `json:"game_id"`
GameName string `json:"game_name"`
BroadcasterLogin string `json:"broadcaster_login"`
DisplayName string `json:"display_name"`
Language string `json:"broadcaster_language"`
Title string `json:"title"`
ThumbnailURL string `json:"thumbnail_url"`
IsLive bool `json:"is_live"`
StartedAt Time `json:"started_at"`
TagIDs []string `json:"tag_ids"`
}
// SearchChannelsResponse is the response from SearchChannels
type SearchChannelsResponse struct {
ResponseCommon
Data ManySearchChannels
}
// SearchChannels searches for Twitch channels based on the given search
// parameters. Unlike GetStreams, this can also return offline channels.
func (c *Client) SearchChannels(params *SearchChannelsParams) (*SearchChannelsResponse, error) {
resp, err := c.get("/search/channels", &ManySearchChannels{}, params)
if err != nil {
return nil, err
}
channels := &SearchChannelsResponse{}
resp.HydrateResponseCommon(&channels.ResponseCommon)
channels.Data.Channels = resp.Data.(*ManySearchChannels).Channels
channels.Data.Pagination = resp.Data.(*ManySearchChannels).Pagination
return channels, nil
}
type GetChannelInformationParams struct {
// Deprecated: BroadcasterID will be removed in a future version. Use BroadcasterIDs instead.
BroadcasterID string `query:"broadcaster_id"`
BroadcasterIDs []string `query:"broadcaster_id"` // Limit 100
}
type EditChannelInformationParams struct {
BroadcasterID string `query:"broadcaster_id" json:"-"`
GameID string `json:"game_id"`
BroadcasterLanguage string `json:"broadcaster_language"`
Title string `json:"title"`
Delay int `json:"delay,omitempty"`
}
type GetChannelInformationResponse struct {
ResponseCommon
Data ManyChannelInformation
}
type EditChannelInformationResponse struct {
ResponseCommon
}
type ManyChannelInformation struct {
Channels []ChannelInformation `json:"data"`
}
type ChannelInformation struct {
BroadcasterID string `json:"broadcaster_id"`
BroadcasterName string `json:"broadcaster_name"`
BroadcasterLanguage string `json:"broadcaster_language"`
GameID string `json:"game_id"`
GameName string `json:"game_name"`
Title string `json:"title"`
Delay int `json:"delay"`
}
func (c *Client) GetChannelInformation(params *GetChannelInformationParams) (*GetChannelInformationResponse, error) {
resp, err := c.get("/channels", &ManyChannelInformation{}, params)
if err != nil {
return nil, err
}
channels := &GetChannelInformationResponse{}
resp.HydrateResponseCommon(&channels.ResponseCommon)
channels.Data.Channels = resp.Data.(*ManyChannelInformation).Channels
return channels, nil
}
func (c *Client) EditChannelInformation(params *EditChannelInformationParams) (*EditChannelInformationResponse, error) {
resp, err := c.patchAsJSON("/channels", &EditChannelInformationResponse{}, params)
if err != nil {
return nil, err
}
channels := &EditChannelInformationResponse{}
resp.HydrateResponseCommon(&channels.ResponseCommon)
return channels, nil
}