author | Mikael Berthe <mikael@lilotux.net> |
Wed, 19 Apr 2017 10:43:38 +0200 | |
changeset 138 | 23d3a518d0ad |
parent 130 | c450bb73f59a |
child 149 | 5f922977d7c7 |
permissions | -rw-r--r-- |
130 | 1 |
/* |
2 |
Copyright 2017 Mikael Berthe |
|
3 |
||
4 |
Licensed under the MIT license. Please see the LICENSE file is this directory. |
|
5 |
*/ |
|
6 |
||
138
23d3a518d0ad
Update package name in source files
Mikael Berthe <mikael@lilotux.net>
parents:
130
diff
changeset
|
7 |
package madon |
88 | 8 |
|
9 |
import ( |
|
10 |
"fmt" |
|
11 |
"strings" |
|
12 |
||
13 |
"github.com/sendgrid/rest" |
|
14 |
) |
|
15 |
||
16 |
// GetTimelines returns a timeline (a list of statuses |
|
127
96a7f2432d27
GetTimelines: Allow '#' as hashtag prefix
Mikael Berthe <mikael@lilotux.net>
parents:
120
diff
changeset
|
17 |
// timeline can be "home", "public", or a hashtag (use ":hashtag" or "#hashtag") |
118
d9c798e09f0a
Add an option to get the local timeline
Mikael Berthe <mikael@lilotux.net>
parents:
98
diff
changeset
|
18 |
// For the public timelines, you can set 'local' to true to get only the |
d9c798e09f0a
Add an option to get the local timeline
Mikael Berthe <mikael@lilotux.net>
parents:
98
diff
changeset
|
19 |
// local instance. |
138
23d3a518d0ad
Update package name in source files
Mikael Berthe <mikael@lilotux.net>
parents:
130
diff
changeset
|
20 |
func (mc *Client) GetTimelines(timeline string, local bool) ([]Status, error) { |
88 | 21 |
var endPoint string |
22 |
||
118
d9c798e09f0a
Add an option to get the local timeline
Mikael Berthe <mikael@lilotux.net>
parents:
98
diff
changeset
|
23 |
switch { |
d9c798e09f0a
Add an option to get the local timeline
Mikael Berthe <mikael@lilotux.net>
parents:
98
diff
changeset
|
24 |
case timeline == "home", timeline == "public": |
88 | 25 |
endPoint = "timelines/" + timeline |
127
96a7f2432d27
GetTimelines: Allow '#' as hashtag prefix
Mikael Berthe <mikael@lilotux.net>
parents:
120
diff
changeset
|
26 |
case strings.HasPrefix(timeline, ":"), strings.HasPrefix(timeline, "#"): |
94
beee0238a82e
Timelines: fix hashtag timelines
Mikael Berthe <mikael@lilotux.net>
parents:
92
diff
changeset
|
27 |
hashtag := timeline[1:] |
beee0238a82e
Timelines: fix hashtag timelines
Mikael Berthe <mikael@lilotux.net>
parents:
92
diff
changeset
|
28 |
if hashtag == "" { |
120 | 29 |
return nil, fmt.Errorf("timelines API: empty hashtag") |
94
beee0238a82e
Timelines: fix hashtag timelines
Mikael Berthe <mikael@lilotux.net>
parents:
92
diff
changeset
|
30 |
} |
beee0238a82e
Timelines: fix hashtag timelines
Mikael Berthe <mikael@lilotux.net>
parents:
92
diff
changeset
|
31 |
endPoint = "timelines/tag/" + hashtag |
118
d9c798e09f0a
Add an option to get the local timeline
Mikael Berthe <mikael@lilotux.net>
parents:
98
diff
changeset
|
32 |
default: |
120 | 33 |
return nil, fmt.Errorf("GetTimelines: bad timelines argument") |
118
d9c798e09f0a
Add an option to get the local timeline
Mikael Berthe <mikael@lilotux.net>
parents:
98
diff
changeset
|
34 |
} |
d9c798e09f0a
Add an option to get the local timeline
Mikael Berthe <mikael@lilotux.net>
parents:
98
diff
changeset
|
35 |
|
120 | 36 |
params := make(apiCallParams) |
37 |
if timeline == "public" && local { |
|
38 |
params["local"] = "true" |
|
88 | 39 |
} |
40 |
||
120 | 41 |
var tl []Status |
138
23d3a518d0ad
Update package name in source files
Mikael Berthe <mikael@lilotux.net>
parents:
130
diff
changeset
|
42 |
if err := mc.apiCall(endPoint, rest.Get, params, &tl); err != nil { |
120 | 43 |
return nil, err |
88 | 44 |
} |
45 |
return tl, nil |
|
46 |
} |