diff --git a/services/billing/mgmt/2018-03-01-preview/billing/enrollmentaccounts.go b/services/billing/mgmt/2018-03-01-preview/billing/enrollmentaccounts.go index 3a42d1a97180..8ad02247a9d7 100644 --- a/services/billing/mgmt/2018-03-01-preview/billing/enrollmentaccounts.go +++ b/services/billing/mgmt/2018-03-01-preview/billing/enrollmentaccounts.go @@ -104,7 +104,8 @@ func (client EnrollmentAccountsClient) GetResponder(resp *http.Response) (result } // List lists the enrollment accounts the caller has access to. -func (client EnrollmentAccountsClient) List(ctx context.Context) (result EnrollmentAccountListResult, err error) { +func (client EnrollmentAccountsClient) List(ctx context.Context) (result EnrollmentAccountListResultPage, err error) { + result.fn = client.listNextResults req, err := client.ListPreparer(ctx) if err != nil { err = autorest.NewErrorWithError(err, "billing.EnrollmentAccountsClient", "List", nil, "Failure preparing request") @@ -113,12 +114,12 @@ func (client EnrollmentAccountsClient) List(ctx context.Context) (result Enrollm resp, err := client.ListSender(req) if err != nil { - result.Response = autorest.Response{Response: resp} + result.ealr.Response = autorest.Response{Response: resp} err = autorest.NewErrorWithError(err, "billing.EnrollmentAccountsClient", "List", resp, "Failure sending request") return } - result, err = client.ListResponder(resp) + result.ealr, err = client.ListResponder(resp) if err != nil { err = autorest.NewErrorWithError(err, "billing.EnrollmentAccountsClient", "List", resp, "Failure responding to request") } @@ -160,3 +161,30 @@ func (client EnrollmentAccountsClient) ListResponder(resp *http.Response) (resul result.Response = autorest.Response{Response: resp} return } + +// listNextResults retrieves the next set of results, if any. +func (client EnrollmentAccountsClient) listNextResults(lastResults EnrollmentAccountListResult) (result EnrollmentAccountListResult, err error) { + req, err := lastResults.enrollmentAccountListResultPreparer() + if err != nil { + return result, autorest.NewErrorWithError(err, "billing.EnrollmentAccountsClient", "listNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "billing.EnrollmentAccountsClient", "listNextResults", resp, "Failure sending next results request") + } + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "billing.EnrollmentAccountsClient", "listNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListComplete enumerates all values, automatically crossing page boundaries as required. +func (client EnrollmentAccountsClient) ListComplete(ctx context.Context) (result EnrollmentAccountListResultIterator, err error) { + result.page, err = client.List(ctx) + return +} diff --git a/services/billing/mgmt/2018-03-01-preview/billing/models.go b/services/billing/mgmt/2018-03-01-preview/billing/models.go index a42ae73112de..a3e7d086387f 100644 --- a/services/billing/mgmt/2018-03-01-preview/billing/models.go +++ b/services/billing/mgmt/2018-03-01-preview/billing/models.go @@ -124,6 +124,99 @@ type EnrollmentAccountListResult struct { NextLink *string `json:"nextLink,omitempty"` } +// EnrollmentAccountListResultIterator provides access to a complete listing of EnrollmentAccount values. +type EnrollmentAccountListResultIterator struct { + i int + page EnrollmentAccountListResultPage +} + +// Next advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +func (iter *EnrollmentAccountListResultIterator) Next() error { + iter.i++ + if iter.i < len(iter.page.Values()) { + return nil + } + err := iter.page.Next() + if err != nil { + iter.i-- + return err + } + iter.i = 0 + return nil +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter EnrollmentAccountListResultIterator) NotDone() bool { + return iter.page.NotDone() && iter.i < len(iter.page.Values()) +} + +// Response returns the raw server response from the last page request. +func (iter EnrollmentAccountListResultIterator) Response() EnrollmentAccountListResult { + return iter.page.Response() +} + +// Value returns the current value or a zero-initialized value if the +// iterator has advanced beyond the end of the collection. +func (iter EnrollmentAccountListResultIterator) Value() EnrollmentAccount { + if !iter.page.NotDone() { + return EnrollmentAccount{} + } + return iter.page.Values()[iter.i] +} + +// IsEmpty returns true if the ListResult contains no values. +func (ealr EnrollmentAccountListResult) IsEmpty() bool { + return ealr.Value == nil || len(*ealr.Value) == 0 +} + +// enrollmentAccountListResultPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (ealr EnrollmentAccountListResult) enrollmentAccountListResultPreparer() (*http.Request, error) { + if ealr.NextLink == nil || len(to.String(ealr.NextLink)) < 1 { + return nil, nil + } + return autorest.Prepare(&http.Request{}, + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(ealr.NextLink))) +} + +// EnrollmentAccountListResultPage contains a page of EnrollmentAccount values. +type EnrollmentAccountListResultPage struct { + fn func(EnrollmentAccountListResult) (EnrollmentAccountListResult, error) + ealr EnrollmentAccountListResult +} + +// Next advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +func (page *EnrollmentAccountListResultPage) Next() error { + next, err := page.fn(page.ealr) + if err != nil { + return err + } + page.ealr = next + return nil +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page EnrollmentAccountListResultPage) NotDone() bool { + return !page.ealr.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page EnrollmentAccountListResultPage) Response() EnrollmentAccountListResult { + return page.ealr +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page EnrollmentAccountListResultPage) Values() []EnrollmentAccount { + if page.ealr.IsEmpty() { + return nil + } + return *page.ealr.Value +} + // EnrollmentAccountProperties the properties of the enrollment account. type EnrollmentAccountProperties struct { // PrincipalName - The account owner's principal name.