1package subscription
2
3// Copyright (c) Microsoft and contributors.  All rights reserved.
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13//
14// See the License for the specific language governing permissions and
15// limitations under the License.
16//
17// Code generated by Microsoft (R) AutoRest Code Generator.
18// Changes may cause incorrect behavior and will be lost if the code is regenerated.
19
20import (
21	"context"
22	"github.com/Azure/go-autorest/autorest"
23	"github.com/Azure/go-autorest/autorest/azure"
24	"net/http"
25)
26
27// DefinitionsOperationMetadataClient is the subscription definitions client provides an interface to create, modify
28// and retrieve azure subscriptions programmatically.
29type DefinitionsOperationMetadataClient struct {
30	BaseClient
31}
32
33// NewDefinitionsOperationMetadataClient creates an instance of the DefinitionsOperationMetadataClient client.
34func NewDefinitionsOperationMetadataClient() DefinitionsOperationMetadataClient {
35	return NewDefinitionsOperationMetadataClientWithBaseURI(DefaultBaseURI)
36}
37
38// NewDefinitionsOperationMetadataClientWithBaseURI creates an instance of the DefinitionsOperationMetadataClient
39// client.
40func NewDefinitionsOperationMetadataClientWithBaseURI(baseURI string) DefinitionsOperationMetadataClient {
41	return DefinitionsOperationMetadataClient{NewWithBaseURI(baseURI)}
42}
43
44// List lists all of the available Microsoft.Subscription API operations.
45func (client DefinitionsOperationMetadataClient) List(ctx context.Context) (result OperationListResultPage, err error) {
46	result.fn = client.listNextResults
47	req, err := client.ListPreparer(ctx)
48	if err != nil {
49		err = autorest.NewErrorWithError(err, "subscription.DefinitionsOperationMetadataClient", "List", nil, "Failure preparing request")
50		return
51	}
52
53	resp, err := client.ListSender(req)
54	if err != nil {
55		result.olr.Response = autorest.Response{Response: resp}
56		err = autorest.NewErrorWithError(err, "subscription.DefinitionsOperationMetadataClient", "List", resp, "Failure sending request")
57		return
58	}
59
60	result.olr, err = client.ListResponder(resp)
61	if err != nil {
62		err = autorest.NewErrorWithError(err, "subscription.DefinitionsOperationMetadataClient", "List", resp, "Failure responding to request")
63	}
64
65	return
66}
67
68// ListPreparer prepares the List request.
69func (client DefinitionsOperationMetadataClient) ListPreparer(ctx context.Context) (*http.Request, error) {
70	const APIVersion = "2017-11-01-preview"
71	queryParameters := map[string]interface{}{
72		"api-version": APIVersion,
73	}
74
75	preparer := autorest.CreatePreparer(
76		autorest.AsGet(),
77		autorest.WithBaseURL(client.BaseURI),
78		autorest.WithPath("/providers/Microsoft.Subscription/operations"),
79		autorest.WithQueryParameters(queryParameters))
80	return preparer.Prepare((&http.Request{}).WithContext(ctx))
81}
82
83// ListSender sends the List request. The method will close the
84// http.Response Body if it receives an error.
85func (client DefinitionsOperationMetadataClient) ListSender(req *http.Request) (*http.Response, error) {
86	return autorest.SendWithSender(client, req,
87		autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
88}
89
90// ListResponder handles the response to the List request. The method always
91// closes the http.Response Body.
92func (client DefinitionsOperationMetadataClient) ListResponder(resp *http.Response) (result OperationListResult, err error) {
93	err = autorest.Respond(
94		resp,
95		client.ByInspecting(),
96		azure.WithErrorUnlessStatusCode(http.StatusOK),
97		autorest.ByUnmarshallingJSON(&result),
98		autorest.ByClosing())
99	result.Response = autorest.Response{Response: resp}
100	return
101}
102
103// listNextResults retrieves the next set of results, if any.
104func (client DefinitionsOperationMetadataClient) listNextResults(lastResults OperationListResult) (result OperationListResult, err error) {
105	req, err := lastResults.operationListResultPreparer()
106	if err != nil {
107		return result, autorest.NewErrorWithError(err, "subscription.DefinitionsOperationMetadataClient", "listNextResults", nil, "Failure preparing next results request")
108	}
109	if req == nil {
110		return
111	}
112	resp, err := client.ListSender(req)
113	if err != nil {
114		result.Response = autorest.Response{Response: resp}
115		return result, autorest.NewErrorWithError(err, "subscription.DefinitionsOperationMetadataClient", "listNextResults", resp, "Failure sending next results request")
116	}
117	result, err = client.ListResponder(resp)
118	if err != nil {
119		err = autorest.NewErrorWithError(err, "subscription.DefinitionsOperationMetadataClient", "listNextResults", resp, "Failure responding to next results request")
120	}
121	return
122}
123
124// ListComplete enumerates all values, automatically crossing page boundaries as required.
125func (client DefinitionsOperationMetadataClient) ListComplete(ctx context.Context) (result OperationListResultIterator, err error) {
126	result.page, err = client.List(ctx)
127	return
128}
129