author | Mikael Berthe <mikael@lilotux.net> |
Sat, 29 Apr 2017 17:27:15 +0200 | |
changeset 156 | 70aadba26338 |
parent 155 | 0c581e0108da |
child 160 | 9f7e683b323f |
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 |
|
156
70aadba26338
Add field "All" to LimitParams, change Limit behaviour
Mikael Berthe <mikael@lilotux.net>
parents:
155
diff
changeset
|
14 |
// If lopt.All is true, several requests will be made until the API server |
70aadba26338
Add field "All" to LimitParams, change Limit behaviour
Mikael Berthe <mikael@lilotux.net>
parents:
155
diff
changeset
|
15 |
// has nothing to return. |
70aadba26338
Add field "All" to LimitParams, change Limit behaviour
Mikael Berthe <mikael@lilotux.net>
parents:
155
diff
changeset
|
16 |
// If lopt.Limit is set (and not All), several queries can be made until the |
70aadba26338
Add field "All" to LimitParams, change Limit behaviour
Mikael Berthe <mikael@lilotux.net>
parents:
155
diff
changeset
|
17 |
// limit is reached. |
149
5f922977d7c7
Add support for limits and paging ({since,max}_id) API parameters
Mikael Berthe <mikael@lilotux.net>
parents:
138
diff
changeset
|
18 |
func (mc *Client) GetFavourites(lopt *LimitParams) ([]Status, error) { |
93 | 19 |
var faves []Status |
155 | 20 |
var links apiLinks |
21 |
err := mc.apiCall("favourites", rest.Get, nil, lopt, &links, &faves) |
|
93 | 22 |
if err != nil { |
120 | 23 |
return nil, err |
93 | 24 |
} |
155 | 25 |
if lopt != nil { // Fetch more pages to reach our limit |
26 |
var faveSlice []Status |
|
156
70aadba26338
Add field "All" to LimitParams, change Limit behaviour
Mikael Berthe <mikael@lilotux.net>
parents:
155
diff
changeset
|
27 |
for (lopt.All || lopt.Limit > len(faves)) && links.next != nil { |
155 | 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 |
} |
|
93 | 37 |
return faves, nil |
38 |
} |