# HG changeset patch # User Mikael Berthe # Date 1492014519 -7200 # Node ID df00ec8423feb7b7bc43972b4bff0eb45069487d # Parent 1b4653f07bfcf961f7eb8b89d5c4a0018b304427 Add timelines support diff -r 1b4653f07bfc -r df00ec8423fe timelines.go --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/timelines.go Wed Apr 12 18:28:39 2017 +0200 @@ -0,0 +1,37 @@ +package gondole + +import ( + "encoding/json" + "fmt" + "strings" + + "github.com/sendgrid/rest" +) + +// GetTimelines returns a timeline (a list of statuses +// timeline can be "home", "public", or a hashtag (":hashtag") +func (g *Client) GetTimelines(timeline string) ([]Status, error) { + var endPoint string + var tl []Status + + if timeline == "home" || timeline == "public" { + endPoint = "timelines/" + timeline + } else if strings.HasPrefix(timeline, ":") { + endPoint = "timelines/tag/" + timeline + } else { + return tl, fmt.Errorf("GetTimelines: bad timelines argument") + } + + req := g.prepareRequest(endPoint) + r, err := rest.API(req) + if err != nil { + return tl, fmt.Errorf("timelines API query: %s", err.Error()) + } + + err = json.Unmarshal([]byte(r.Body), &tl) + if err != nil { + return tl, fmt.Errorf("timelines API: %s", err.Error()) + } + + return tl, nil +}