author | Mikael Berthe <mikael@lilotux.net> |
Sat, 29 Apr 2017 12:16:16 +0200 | |
changeset 155 | 0c581e0108da |
parent 149 | 5f922977d7c7 |
child 156 | 70aadba26338 |
permissions | -rw-r--r-- |
130 | 1 |
/* |
2 |
Copyright 2017 Mikael Berthe |
|
3 |
||
4 |
Licensed under the MIT license. Please see the LICENSE file is this directory. |
|
5 |
*/ |
|
6 |
||
138
23d3a518d0ad
Update package name in source files
Mikael Berthe <mikael@lilotux.net>
parents:
130
diff
changeset
|
7 |
package madon |
93 | 8 |
|
9 |
import ( |
|
10 |
"github.com/sendgrid/rest" |
|
11 |
) |
|
12 |
||
13 |
// GetFavourites returns the list of the user's favourites |
|
149
5f922977d7c7
Add support for limits and paging ({since,max}_id) API parameters
Mikael Berthe <mikael@lilotux.net>
parents:
138
diff
changeset
|
14 |
func (mc *Client) GetFavourites(lopt *LimitParams) ([]Status, error) { |
93 | 15 |
var faves []Status |
155 | 16 |
var links apiLinks |
17 |
err := mc.apiCall("favourites", rest.Get, nil, lopt, &links, &faves) |
|
93 | 18 |
if err != nil { |
120 | 19 |
return nil, err |
93 | 20 |
} |
155 | 21 |
if lopt != nil { // Fetch more pages to reach our limit |
22 |
var faveSlice []Status |
|
23 |
for lopt.Limit > len(faves) && links.next != nil { |
|
24 |
newlopt := links.next |
|
25 |
links = apiLinks{} |
|
26 |
if err := mc.apiCall("favourites", rest.Get, nil, newlopt, &links, &faveSlice); err != nil { |
|
27 |
return nil, err |
|
28 |
} |
|
29 |
faves = append(faves, faveSlice...) |
|
30 |
faveSlice = faveSlice[:0] // Clear struct |
|
31 |
} |
|
32 |
} |
|
93 | 33 |
return faves, nil |
34 |
} |