author | Mikael Berthe <mikael@lilotux.net> |
Thu, 13 Apr 2017 00:17:57 +0200 | |
changeset 98 | 5d803adfc57e |
parent 93 | d427d8aa75f9 |
child 120 | 579912e9d0ef |
permissions | -rw-r--r-- |
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 { |
|
98
5d803adfc57e
Use Error entity structure
Mikael Berthe <mikael@lilotux.net>
parents:
93
diff
changeset
|
23 |
var errorRes Error |
5d803adfc57e
Use Error entity structure
Mikael Berthe <mikael@lilotux.net>
parents:
93
diff
changeset
|
24 |
err2 := json.Unmarshal([]byte(r.Body), &errorRes) |
93 | 25 |
if err2 == nil { |
98
5d803adfc57e
Use Error entity structure
Mikael Berthe <mikael@lilotux.net>
parents:
93
diff
changeset
|
26 |
return faves, fmt.Errorf("%s", errorRes.Text) |
93 | 27 |
} |
28 |
return faves, fmt.Errorf("favourites API: %s", err.Error()) |
|
29 |
} |
|
30 |
||
31 |
return faves, nil |
|
32 |
} |