1package dtl
2
3// Copyright (c) Microsoft Corporation. All rights reserved.
4// Licensed under the MIT License. See License.txt in the project root for license information.
5//
6// Code generated by Microsoft (R) AutoRest Code Generator.
7// Changes may cause incorrect behavior and will be lost if the code is regenerated.
8
9import (
10	"context"
11	"github.com/Azure/go-autorest/autorest"
12	"github.com/Azure/go-autorest/autorest/azure"
13	"github.com/Azure/go-autorest/tracing"
14	"net/http"
15)
16
17// ProviderOperationsClient is the the DevTest Labs Client.
18type ProviderOperationsClient struct {
19	BaseClient
20}
21
22// NewProviderOperationsClient creates an instance of the ProviderOperationsClient client.
23func NewProviderOperationsClient(subscriptionID string) ProviderOperationsClient {
24	return NewProviderOperationsClientWithBaseURI(DefaultBaseURI, subscriptionID)
25}
26
27// NewProviderOperationsClientWithBaseURI creates an instance of the ProviderOperationsClient client using a custom
28// endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure
29// stack).
30func NewProviderOperationsClientWithBaseURI(baseURI string, subscriptionID string) ProviderOperationsClient {
31	return ProviderOperationsClient{NewWithBaseURI(baseURI, subscriptionID)}
32}
33
34// List result of the request to list REST API operations
35func (client ProviderOperationsClient) List(ctx context.Context) (result ProviderOperationResultPage, err error) {
36	if tracing.IsEnabled() {
37		ctx = tracing.StartSpan(ctx, fqdn+"/ProviderOperationsClient.List")
38		defer func() {
39			sc := -1
40			if result.por.Response.Response != nil {
41				sc = result.por.Response.Response.StatusCode
42			}
43			tracing.EndSpan(ctx, sc, err)
44		}()
45	}
46	result.fn = client.listNextResults
47	req, err := client.ListPreparer(ctx)
48	if err != nil {
49		err = autorest.NewErrorWithError(err, "dtl.ProviderOperationsClient", "List", nil, "Failure preparing request")
50		return
51	}
52
53	resp, err := client.ListSender(req)
54	if err != nil {
55		result.por.Response = autorest.Response{Response: resp}
56		err = autorest.NewErrorWithError(err, "dtl.ProviderOperationsClient", "List", resp, "Failure sending request")
57		return
58	}
59
60	result.por, err = client.ListResponder(resp)
61	if err != nil {
62		err = autorest.NewErrorWithError(err, "dtl.ProviderOperationsClient", "List", resp, "Failure responding to request")
63		return
64	}
65	if result.por.hasNextLink() && result.por.IsEmpty() {
66		err = result.NextWithContext(ctx)
67		return
68	}
69
70	return
71}
72
73// ListPreparer prepares the List request.
74func (client ProviderOperationsClient) ListPreparer(ctx context.Context) (*http.Request, error) {
75	const APIVersion = "2016-05-15"
76	queryParameters := map[string]interface{}{
77		"api-version": APIVersion,
78	}
79
80	preparer := autorest.CreatePreparer(
81		autorest.AsGet(),
82		autorest.WithBaseURL(client.BaseURI),
83		autorest.WithPath("/providers/Microsoft.DevTestLab/operations"),
84		autorest.WithQueryParameters(queryParameters))
85	return preparer.Prepare((&http.Request{}).WithContext(ctx))
86}
87
88// ListSender sends the List request. The method will close the
89// http.Response Body if it receives an error.
90func (client ProviderOperationsClient) ListSender(req *http.Request) (*http.Response, error) {
91	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
92}
93
94// ListResponder handles the response to the List request. The method always
95// closes the http.Response Body.
96func (client ProviderOperationsClient) ListResponder(resp *http.Response) (result ProviderOperationResult, err error) {
97	err = autorest.Respond(
98		resp,
99		azure.WithErrorUnlessStatusCode(http.StatusOK),
100		autorest.ByUnmarshallingJSON(&result),
101		autorest.ByClosing())
102	result.Response = autorest.Response{Response: resp}
103	return
104}
105
106// listNextResults retrieves the next set of results, if any.
107func (client ProviderOperationsClient) listNextResults(ctx context.Context, lastResults ProviderOperationResult) (result ProviderOperationResult, err error) {
108	req, err := lastResults.providerOperationResultPreparer(ctx)
109	if err != nil {
110		return result, autorest.NewErrorWithError(err, "dtl.ProviderOperationsClient", "listNextResults", nil, "Failure preparing next results request")
111	}
112	if req == nil {
113		return
114	}
115	resp, err := client.ListSender(req)
116	if err != nil {
117		result.Response = autorest.Response{Response: resp}
118		return result, autorest.NewErrorWithError(err, "dtl.ProviderOperationsClient", "listNextResults", resp, "Failure sending next results request")
119	}
120	result, err = client.ListResponder(resp)
121	if err != nil {
122		err = autorest.NewErrorWithError(err, "dtl.ProviderOperationsClient", "listNextResults", resp, "Failure responding to next results request")
123	}
124	return
125}
126
127// ListComplete enumerates all values, automatically crossing page boundaries as required.
128func (client ProviderOperationsClient) ListComplete(ctx context.Context) (result ProviderOperationResultIterator, err error) {
129	if tracing.IsEnabled() {
130		ctx = tracing.StartSpan(ctx, fqdn+"/ProviderOperationsClient.List")
131		defer func() {
132			sc := -1
133			if result.Response().Response.Response != nil {
134				sc = result.page.Response().Response.Response.StatusCode
135			}
136			tracing.EndSpan(ctx, sc, err)
137		}()
138	}
139	result.page, err = client.List(ctx)
140	return
141}
142