9 import ( |
9 import ( |
10 "github.com/sendgrid/rest" |
10 "github.com/sendgrid/rest" |
11 ) |
11 ) |
12 |
12 |
13 // GetFavourites returns the list of the user's favourites |
13 // GetFavourites returns the list of the user's favourites |
|
14 // If lopt.All is true, several requests will be made until the API server |
|
15 // has nothing to return. |
|
16 // If lopt.Limit is set (and not All), several queries can be made until the |
|
17 // limit is reached. |
14 func (mc *Client) GetFavourites(lopt *LimitParams) ([]Status, error) { |
18 func (mc *Client) GetFavourites(lopt *LimitParams) ([]Status, error) { |
15 var faves []Status |
19 var faves []Status |
16 var links apiLinks |
20 var links apiLinks |
17 err := mc.apiCall("favourites", rest.Get, nil, lopt, &links, &faves) |
21 err := mc.apiCall("favourites", rest.Get, nil, lopt, &links, &faves) |
18 if err != nil { |
22 if err != nil { |
19 return nil, err |
23 return nil, err |
20 } |
24 } |
21 if lopt != nil { // Fetch more pages to reach our limit |
25 if lopt != nil { // Fetch more pages to reach our limit |
22 var faveSlice []Status |
26 var faveSlice []Status |
23 for lopt.Limit > len(faves) && links.next != nil { |
27 for (lopt.All || lopt.Limit > len(faves)) && links.next != nil { |
24 newlopt := links.next |
28 newlopt := links.next |
25 links = apiLinks{} |
29 links = apiLinks{} |
26 if err := mc.apiCall("favourites", rest.Get, nil, newlopt, &links, &faveSlice); err != nil { |
30 if err := mc.apiCall("favourites", rest.Get, nil, newlopt, &links, &faveSlice); err != nil { |
27 return nil, err |
31 return nil, err |
28 } |
32 } |