/
streams.go
44 lines (40 loc) · 1.14 KB
/
streams.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
package twitch2go
import (
"encoding/json"
"github.com/juju/errors"
)
// GetStreamByChannel returns a StreamResponse for the given channel
func (c *Client) GetStreamByChannel(channelID string) (*Stream, error) {
url := "/streams/" + channelID
// Do the request
resp, err := c.do("GET", url, &doOptions{})
if err != nil {
return nil, errors.Annotate(err, "GetStreamByChannel")
}
defer resp.Body.Close()
stream := &StreamResponse{}
err = json.NewDecoder(resp.Body).Decode(&stream)
if err != nil {
return nil, errors.Annotate(err, "Error decoding JSON")
}
return &stream.Stream, nil
}
// GetFollowedStreams returns a list of streams the user follows, based on user auth token.
func (c *Client) GetFollowedStreams(oauth string) (*FollowedStream, error) {
url := "/streams/followed"
opts := &doOptions{
oauth: oauth,
}
// Do the request
resp, err := c.do("GET", url, opts)
if err != nil {
return nil, errors.Annotate(err, "GetFollowedStreams")
}
defer resp.Body.Close()
fs := &FollowedStream{}
err = json.NewDecoder(resp.Body).Decode(&fs)
if err != nil {
return nil, errors.Annotate(err, "Error decoding json")
}
return fs, nil
}