88
|
1 |
package gondole |
|
2 |
|
|
3 |
import ( |
|
4 |
"encoding/json" |
|
5 |
"fmt" |
|
6 |
"strings" |
|
7 |
|
|
8 |
"github.com/sendgrid/rest" |
|
9 |
) |
|
10 |
|
|
11 |
// GetTimelines returns a timeline (a list of statuses |
|
12 |
// timeline can be "home", "public", or a hashtag (":hashtag") |
|
13 |
func (g *Client) GetTimelines(timeline string) ([]Status, error) { |
|
14 |
var endPoint string |
|
15 |
var tl []Status |
|
16 |
|
|
17 |
if timeline == "home" || timeline == "public" { |
|
18 |
endPoint = "timelines/" + timeline |
|
19 |
} else if strings.HasPrefix(timeline, ":") { |
|
20 |
endPoint = "timelines/tag/" + timeline |
|
21 |
} else { |
|
22 |
return tl, fmt.Errorf("GetTimelines: bad timelines argument") |
|
23 |
} |
|
24 |
|
|
25 |
req := g.prepareRequest(endPoint) |
|
26 |
r, err := rest.API(req) |
|
27 |
if err != nil { |
|
28 |
return tl, fmt.Errorf("timelines API query: %s", err.Error()) |
|
29 |
} |
|
30 |
|
|
31 |
err = json.Unmarshal([]byte(r.Body), &tl) |
|
32 |
if err != nil { |
|
33 |
return tl, fmt.Errorf("timelines API: %s", err.Error()) |
|
34 |
} |
|
35 |
|
|
36 |
return tl, nil |
|
37 |
} |