|
1 /* |
|
2 Copyright 2017-2018 Mikael Berthe |
|
3 |
|
4 Licensed under the MIT license. Please see the LICENSE file is this directory. |
|
5 */ |
|
6 |
|
7 package madon |
|
8 |
|
9 import ( |
|
10 "strings" |
|
11 |
|
12 "github.com/pkg/errors" |
|
13 ) |
|
14 |
|
15 // GetTimelines returns a timeline (a list of statuses) |
|
16 // timeline can be "home", "public", "direct", a hashtag (use ":hashtag" or |
|
17 // "#hashtag") or a list (use "!N", e.g. "!42" for list ID #42). |
|
18 // For the public timelines, you can set 'local' to true to get only the |
|
19 // local instance. |
|
20 // Set 'onlyMedia' to true to only get statuses that have media attachments. |
|
21 // If lopt.All is true, several requests will be made until the API server |
|
22 // has nothing to return. |
|
23 // If lopt.Limit is set (and not All), several queries can be made until the |
|
24 // limit is reached. |
|
25 func (mc *Client) GetTimelines(timeline string, local, onlyMedia bool, lopt *LimitParams) ([]Status, error) { |
|
26 var endPoint string |
|
27 |
|
28 switch { |
|
29 case timeline == "home", timeline == "public", timeline == "direct": |
|
30 endPoint = "timelines/" + timeline |
|
31 case strings.HasPrefix(timeline, ":"), strings.HasPrefix(timeline, "#"): |
|
32 hashtag := timeline[1:] |
|
33 if hashtag == "" { |
|
34 return nil, errors.New("timelines API: empty hashtag") |
|
35 } |
|
36 endPoint = "timelines/tag/" + hashtag |
|
37 case len(timeline) > 1 && strings.HasPrefix(timeline, "!"): |
|
38 // Check the timeline is a number |
|
39 for _, n := range timeline[1:] { |
|
40 if n < '0' || n > '9' { |
|
41 return nil, errors.New("timelines API: invalid list ID") |
|
42 } |
|
43 } |
|
44 endPoint = "timelines/list/" + timeline[1:] |
|
45 default: |
|
46 return nil, errors.New("GetTimelines: bad timelines argument") |
|
47 } |
|
48 |
|
49 params := make(apiCallParams) |
|
50 if timeline == "public" && local { |
|
51 params["local"] = "true" |
|
52 } |
|
53 if onlyMedia { |
|
54 params["only_media"] = "true" |
|
55 } |
|
56 |
|
57 return mc.getMultipleStatuses(endPoint, params, lopt) |
|
58 } |