Add field "All" to LimitParams, change Limit behaviour
If All is true, the library will send several requests (if needed) until
the API server has sent all the results.
If not, and if a Limit is set, the library will try to fetch at least
this number of results.
--- a/account.go Sat Apr 29 12:16:16 2017 +0200
+++ b/account.go Sat Apr 29 17:27:15 2017 +0200
@@ -69,6 +69,8 @@
// The operation 'op' can be "followers", "following", "search", "blocks",
// "mutes", "follow_requests".
// The id is optional and depends on the operation.
+// If opts.All is true, several requests will be made until the API server
+// has nothing to return.
func (mc *Client) getMultipleAccounts(op string, opts *getAccountsOptions) ([]Account, error) {
var endPoint string
var lopt *LimitParams
@@ -112,7 +114,7 @@
}
if lopt != nil { // Fetch more pages to reach our limit
var accountSlice []Account
- for lopt.Limit > len(accounts) && links.next != nil {
+ for (lopt.All || lopt.Limit > len(accounts)) && links.next != nil {
newlopt := links.next
links = apiLinks{}
if err := mc.apiCall(endPoint, rest.Get, params, newlopt, &links, &accountSlice); err != nil {
@@ -308,6 +310,10 @@
// GetAccountStatuses returns a list of status entities for the given account
// If onlyMedia is true, returns only statuses that have media attachments.
// If excludeReplies is true, skip statuses that reply to other statuses.
+// If lopt.All is true, several requests will be made until the API server
+// has nothing to return.
+// If lopt.Limit is set (and not All), several queries can be made until the
+// limit is reached.
func (mc *Client) GetAccountStatuses(accountID int, onlyMedia, excludeReplies bool, lopt *LimitParams) ([]Status, error) {
if accountID < 1 {
return nil, ErrInvalidID
@@ -329,7 +335,7 @@
}
if lopt != nil { // Fetch more pages to reach our limit
var statusSlice []Status
- for lopt.Limit > len(sl) && links.next != nil {
+ for (lopt.All || lopt.Limit > len(sl)) && links.next != nil {
newlopt := links.next
links = apiLinks{}
if err := mc.apiCall(endPoint, rest.Get, params, newlopt, &links, &statusSlice); err != nil {
--- a/favourites.go Sat Apr 29 12:16:16 2017 +0200
+++ b/favourites.go Sat Apr 29 17:27:15 2017 +0200
@@ -11,6 +11,10 @@
)
// GetFavourites returns the list of the user's favourites
+// If lopt.All is true, several requests will be made until the API server
+// has nothing to return.
+// If lopt.Limit is set (and not All), several queries can be made until the
+// limit is reached.
func (mc *Client) GetFavourites(lopt *LimitParams) ([]Status, error) {
var faves []Status
var links apiLinks
@@ -20,7 +24,7 @@
}
if lopt != nil { // Fetch more pages to reach our limit
var faveSlice []Status
- for lopt.Limit > len(faves) && links.next != nil {
+ for (lopt.All || lopt.Limit > len(faves)) && links.next != nil {
newlopt := links.next
links = apiLinks{}
if err := mc.apiCall("favourites", rest.Get, nil, newlopt, &links, &faveSlice); err != nil {
--- a/madon.go Sat Apr 29 12:16:16 2017 +0200
+++ b/madon.go Sat Apr 29 17:27:15 2017 +0200
@@ -13,7 +13,9 @@
// LimitParams contains common limit/paging options for the Mastodon REST API
type LimitParams struct {
- SinceID, MaxID, Limit int
+ Limit int // Number of items per query
+ SinceID, MaxID int // Boundaries
+ All bool // Get as many items as possible
}
// apiCallParams is a map with the parameters for an API call
--- a/notifications.go Sat Apr 29 12:16:16 2017 +0200
+++ b/notifications.go Sat Apr 29 17:27:15 2017 +0200
@@ -13,6 +13,10 @@
)
// GetNotifications returns the list of the user's notifications
+// If lopt.All is true, several requests will be made until the API server
+// has nothing to return.
+// If lopt.Limit is set (and not All), several queries can be made until the
+// limit is reached.
func (mc *Client) GetNotifications(lopt *LimitParams) ([]Notification, error) {
var notifications []Notification
var links apiLinks
@@ -21,7 +25,7 @@
}
if lopt != nil { // Fetch more pages to reach our limit
var notifSlice []Notification
- for lopt.Limit > len(notifications) && links.next != nil {
+ for (lopt.All || lopt.Limit > len(notifications)) && links.next != nil {
newlopt := links.next
links = apiLinks{}
if err := mc.apiCall("notifications", rest.Get, nil, newlopt, &links, ¬ifSlice); err != nil {
--- a/report.go Sat Apr 29 12:16:16 2017 +0200
+++ b/report.go Sat Apr 29 17:27:15 2017 +0200
@@ -14,6 +14,7 @@
)
// GetReports returns the current user's reports
+// (I don't know if the limit options are used by the API server.)
func (mc *Client) GetReports(lopt *LimitParams) ([]Report, error) {
var reports []Report
if err := mc.apiCall("reports", rest.Get, nil, lopt, nil, &reports); err != nil {
--- a/timelines.go Sat Apr 29 12:16:16 2017 +0200
+++ b/timelines.go Sat Apr 29 17:27:15 2017 +0200
@@ -17,6 +17,10 @@
// timeline can be "home", "public", or a hashtag (use ":hashtag" or "#hashtag")
// For the public timelines, you can set 'local' to true to get only the
// local instance.
+// If lopt.All is true, several requests will be made until the API server
+// has nothing to return.
+// If lopt.Limit is set (and not All), several queries can be made until the
+// limit is reached.
func (mc *Client) GetTimelines(timeline string, local bool, lopt *LimitParams) ([]Status, error) {
var endPoint string
@@ -45,7 +49,7 @@
}
if lopt != nil { // Fetch more pages to reach our limit
var statusSlice []Status
- for lopt.Limit > len(tl) && links.next != nil {
+ for (lopt.All || lopt.Limit > len(tl)) && links.next != nil {
newlopt := links.next
links = apiLinks{}
if err := mc.apiCall(endPoint, rest.Get, params, newlopt, &links, &statusSlice); err != nil {