4 Licensed under the MIT license. Please see the LICENSE file is this directory. |
4 Licensed under the MIT license. Please see the LICENSE file is this directory. |
5 */ |
5 */ |
6 |
6 |
7 package madon |
7 package madon |
8 |
8 |
9 import ( |
|
10 "github.com/sendgrid/rest" |
|
11 ) |
|
12 |
|
13 // GetFavourites returns the list of the user's favourites |
9 // GetFavourites returns the list of the user's favourites |
14 // If lopt.All is true, several requests will be made until the API server |
10 // If lopt.All is true, several requests will be made until the API server |
15 // has nothing to return. |
11 // has nothing to return. |
16 // If lopt.Limit is set (and not All), several queries can be made until the |
12 // If lopt.Limit is set (and not All), several queries can be made until the |
17 // limit is reached. |
13 // limit is reached. |
18 func (mc *Client) GetFavourites(lopt *LimitParams) ([]Status, error) { |
14 func (mc *Client) GetFavourites(lopt *LimitParams) ([]Status, error) { |
19 var faves []Status |
15 return mc.getMultipleStatuses("favourites", nil, lopt) |
20 var links apiLinks |
|
21 err := mc.apiCall("favourites", rest.Get, nil, lopt, &links, &faves) |
|
22 if err != nil { |
|
23 return nil, err |
|
24 } |
|
25 if lopt != nil { // Fetch more pages to reach our limit |
|
26 var faveSlice []Status |
|
27 for (lopt.All || lopt.Limit > len(faves)) && links.next != nil { |
|
28 newlopt := links.next |
|
29 links = apiLinks{} |
|
30 if err := mc.apiCall("favourites", rest.Get, nil, newlopt, &links, &faveSlice); err != nil { |
|
31 return nil, err |
|
32 } |
|
33 faves = append(faves, faveSlice...) |
|
34 faveSlice = faveSlice[:0] // Clear struct |
|
35 } |
|
36 } |
|
37 return faves, nil |
|
38 } |
16 } |