author | Mikael Berthe <mikael@lilotux.net> |
Sat, 15 Apr 2017 10:26:36 +0200 | |
changeset 120 | 579912e9d0ef |
parent 118 | d9c798e09f0a |
child 127 | 96a7f2432d27 |
permissions | -rw-r--r-- |
88 | 1 |
package gondole |
2 |
||
3 |
import ( |
|
4 |
"fmt" |
|
5 |
"strings" |
|
6 |
||
7 |
"github.com/sendgrid/rest" |
|
8 |
) |
|
9 |
||
10 |
// GetTimelines returns a timeline (a list of statuses |
|
118
d9c798e09f0a
Add an option to get the local timeline
Mikael Berthe <mikael@lilotux.net>
parents:
98
diff
changeset
|
11 |
// timeline can be "home", "public", or a hashtag (use ":hashtag") |
d9c798e09f0a
Add an option to get the local timeline
Mikael Berthe <mikael@lilotux.net>
parents:
98
diff
changeset
|
12 |
// 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
|
13 |
// local instance. |
d9c798e09f0a
Add an option to get the local timeline
Mikael Berthe <mikael@lilotux.net>
parents:
98
diff
changeset
|
14 |
func (g *Client) GetTimelines(timeline string, local bool) ([]Status, error) { |
88 | 15 |
var endPoint string |
16 |
||
118
d9c798e09f0a
Add an option to get the local timeline
Mikael Berthe <mikael@lilotux.net>
parents:
98
diff
changeset
|
17 |
switch { |
d9c798e09f0a
Add an option to get the local timeline
Mikael Berthe <mikael@lilotux.net>
parents:
98
diff
changeset
|
18 |
case timeline == "home", timeline == "public": |
88 | 19 |
endPoint = "timelines/" + timeline |
118
d9c798e09f0a
Add an option to get the local timeline
Mikael Berthe <mikael@lilotux.net>
parents:
98
diff
changeset
|
20 |
case strings.HasPrefix(timeline, ":"): |
94
beee0238a82e
Timelines: fix hashtag timelines
Mikael Berthe <mikael@lilotux.net>
parents:
92
diff
changeset
|
21 |
hashtag := timeline[1:] |
beee0238a82e
Timelines: fix hashtag timelines
Mikael Berthe <mikael@lilotux.net>
parents:
92
diff
changeset
|
22 |
if hashtag == "" { |
120 | 23 |
return nil, fmt.Errorf("timelines API: empty hashtag") |
94
beee0238a82e
Timelines: fix hashtag timelines
Mikael Berthe <mikael@lilotux.net>
parents:
92
diff
changeset
|
24 |
} |
beee0238a82e
Timelines: fix hashtag timelines
Mikael Berthe <mikael@lilotux.net>
parents:
92
diff
changeset
|
25 |
endPoint = "timelines/tag/" + hashtag |
118
d9c798e09f0a
Add an option to get the local timeline
Mikael Berthe <mikael@lilotux.net>
parents:
98
diff
changeset
|
26 |
default: |
120 | 27 |
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
|
28 |
} |
d9c798e09f0a
Add an option to get the local timeline
Mikael Berthe <mikael@lilotux.net>
parents:
98
diff
changeset
|
29 |
|
120 | 30 |
params := make(apiCallParams) |
31 |
if timeline == "public" && local { |
|
32 |
params["local"] = "true" |
|
88 | 33 |
} |
34 |
||
120 | 35 |
var tl []Status |
36 |
if err := g.apiCall(endPoint, rest.Get, params, &tl); err != nil { |
|
37 |
return nil, err |
|
88 | 38 |
} |
39 |
return tl, nil |
|
40 |
} |