--- a/timelines.go Sat Apr 15 00:39:43 2017 +0200
+++ b/timelines.go Sat Apr 15 10:26:36 2017 +0200
@@ -1,7 +1,6 @@
package gondole
import (
- "encoding/json"
"fmt"
"strings"
@@ -14,7 +13,6 @@
// local instance.
func (g *Client) GetTimelines(timeline string, local bool) ([]Status, error) {
var endPoint string
- var tl []Status
switch {
case timeline == "home", timeline == "public":
@@ -22,33 +20,21 @@
case strings.HasPrefix(timeline, ":"):
hashtag := timeline[1:]
if hashtag == "" {
- return tl, fmt.Errorf("timelines API: empty hashtag")
+ return nil, fmt.Errorf("timelines API: empty hashtag")
}
endPoint = "timelines/tag/" + hashtag
default:
- return tl, fmt.Errorf("GetTimelines: bad timelines argument")
- }
-
- req := g.prepareRequest(endPoint)
-
- if timeline == "public" && local {
- req.QueryParams["local"] = "true"
+ return nil, fmt.Errorf("GetTimelines: bad timelines argument")
}
- r, err := rest.API(req)
- if err != nil {
- return tl, fmt.Errorf("timelines API query: %s", err.Error())
+ params := make(apiCallParams)
+ if timeline == "public" && local {
+ params["local"] = "true"
}
- err = json.Unmarshal([]byte(r.Body), &tl)
- if err != nil {
- var errorRes Error
- err2 := json.Unmarshal([]byte(r.Body), &errorRes)
- if err2 == nil {
- return tl, fmt.Errorf("%s", errorRes.Text)
- }
- return tl, fmt.Errorf("timelines API: %s", err.Error())
+ var tl []Status
+ if err := g.apiCall(endPoint, rest.Get, params, &tl); err != nil {
+ return nil, err
}
-
return tl, nil
}