forked from McKael/madon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
timelines.go
58 lines (50 loc) · 1.74 KB
/
timelines.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
/*
Copyright 2017-2018 Mikael Berthe
Licensed under the MIT license. Please see the LICENSE file is this directory.
*/
package madon
import (
"strings"
"github.com/pkg/errors"
)
// GetTimelines returns a timeline (a list of statuses)
// timeline can be "home", "public", "direct", a hashtag (use ":hashtag" or
// "#hashtag") or a list (use "!N", e.g. "!42" for list ID #42).
// For the public timelines, you can set 'local' to true to get only the
// local instance.
// Set 'onlyMedia' to true to only get statuses that have media attachments.
// If lopt.All is true, several requests will be made until the API server
// has nothing to return.
// If lopt.Limit is set (and not All), several queries can be made until the
// limit is reached.
func (mc *Client) GetTimelines(timeline string, local, onlyMedia bool, lopt *LimitParams) ([]Status, error) {
var endPoint string
switch {
case timeline == "home", timeline == "public", timeline == "direct":
endPoint = "timelines/" + timeline
case strings.HasPrefix(timeline, ":"), strings.HasPrefix(timeline, "#"):
hashtag := timeline[1:]
if hashtag == "" {
return nil, errors.New("timelines API: empty hashtag")
}
endPoint = "timelines/tag/" + hashtag
case len(timeline) > 1 && strings.HasPrefix(timeline, "!"):
// Check the timeline is a number
for _, n := range timeline[1:] {
if n < '0' || n > '9' {
return nil, errors.New("timelines API: invalid list ID")
}
}
endPoint = "timelines/list/" + timeline[1:]
default:
return nil, errors.New("GetTimelines: bad timelines argument")
}
params := make(apiCallParams)
if timeline == "public" && local {
params["local"] = "true"
}
if onlyMedia {
params["only_media"] = "true"
}
return mc.getMultipleStatuses(endPoint, params, lopt)
}