favourites.go
changeset 120 579912e9d0ef
parent 98 5d803adfc57e
child 130 c450bb73f59a
equal deleted inserted replaced
119:22c8c58ad61b 120:579912e9d0ef
     1 package gondole
     1 package gondole
     2 
     2 
     3 import (
     3 import (
     4 	"encoding/json"
       
     5 	"fmt"
       
     6 
       
     7 	"github.com/sendgrid/rest"
     4 	"github.com/sendgrid/rest"
     8 )
     5 )
     9 
     6 
    10 // GetFavourites returns the list of the user's favourites
     7 // GetFavourites returns the list of the user's favourites
    11 func (g *Client) GetFavourites() ([]Status, error) {
     8 func (g *Client) GetFavourites() ([]Status, error) {
    12 	var faves []Status
     9 	var faves []Status
    13 
    10 	err := g.apiCall("favourites", rest.Get, nil, &faves)
    14 	req := g.prepareRequest("favourites")
       
    15 	r, err := rest.API(req)
       
    16 	if err != nil {
    11 	if err != nil {
    17 		return faves, fmt.Errorf("favourites API query: %s", err.Error())
    12 		return nil, err
    18 	}
    13 	}
    19 
       
    20 	println(r.Body)
       
    21 	err = json.Unmarshal([]byte(r.Body), &faves)
       
    22 	if err != nil {
       
    23 		var errorRes Error
       
    24 		err2 := json.Unmarshal([]byte(r.Body), &errorRes)
       
    25 		if err2 == nil {
       
    26 			return faves, fmt.Errorf("%s", errorRes.Text)
       
    27 		}
       
    28 		return faves, fmt.Errorf("favourites API: %s", err.Error())
       
    29 	}
       
    30 
       
    31 	return faves, nil
    14 	return faves, nil
    32 }
    15 }