93
|
1 |
package gondole |
|
2 |
|
|
3 |
import ( |
|
4 |
"encoding/json" |
|
5 |
"fmt" |
|
6 |
|
|
7 |
"github.com/sendgrid/rest" |
|
8 |
) |
|
9 |
|
|
10 |
// GetFavourites returns the list of the user's favourites |
|
11 |
func (g *Client) GetFavourites() ([]Status, error) { |
|
12 |
var faves []Status |
|
13 |
|
|
14 |
req := g.prepareRequest("favourites") |
|
15 |
r, err := rest.API(req) |
|
16 |
if err != nil { |
|
17 |
return faves, fmt.Errorf("favourites API query: %s", err.Error()) |
|
18 |
} |
|
19 |
|
|
20 |
println(r.Body) |
|
21 |
err = json.Unmarshal([]byte(r.Body), &faves) |
|
22 |
if err != nil { |
|
23 |
var res struct { |
|
24 |
Error string `json:"error"` |
|
25 |
} |
|
26 |
err2 := json.Unmarshal([]byte(r.Body), &res) |
|
27 |
if err2 == nil { |
|
28 |
return faves, fmt.Errorf("%s", res.Error) |
|
29 |
} |
|
30 |
return faves, fmt.Errorf("favourites API: %s", err.Error()) |
|
31 |
} |
|
32 |
|
|
33 |
return faves, nil |
|
34 |
} |