1package media
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	"github.com/Azure/go-autorest/tracing"
25	"net/http"
26)
27
28// OperationsClient is the client for the Operations methods of the Media service.
29type OperationsClient struct {
30	BaseClient
31}
32
33// NewOperationsClient creates an instance of the OperationsClient client.
34func NewOperationsClient(subscriptionID string) OperationsClient {
35	return NewOperationsClientWithBaseURI(DefaultBaseURI, subscriptionID)
36}
37
38// NewOperationsClientWithBaseURI creates an instance of the OperationsClient client using a custom endpoint.  Use this
39// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
40func NewOperationsClientWithBaseURI(baseURI string, subscriptionID string) OperationsClient {
41	return OperationsClient{NewWithBaseURI(baseURI, subscriptionID)}
42}
43
44// List lists all the Media Services operations.
45func (client OperationsClient) List(ctx context.Context) (result OperationCollectionPage, err error) {
46	if tracing.IsEnabled() {
47		ctx = tracing.StartSpan(ctx, fqdn+"/OperationsClient.List")
48		defer func() {
49			sc := -1
50			if result.oc.Response.Response != nil {
51				sc = result.oc.Response.Response.StatusCode
52			}
53			tracing.EndSpan(ctx, sc, err)
54		}()
55	}
56	result.fn = client.listNextResults
57	req, err := client.ListPreparer(ctx)
58	if err != nil {
59		err = autorest.NewErrorWithError(err, "media.OperationsClient", "List", nil, "Failure preparing request")
60		return
61	}
62
63	resp, err := client.ListSender(req)
64	if err != nil {
65		result.oc.Response = autorest.Response{Response: resp}
66		err = autorest.NewErrorWithError(err, "media.OperationsClient", "List", resp, "Failure sending request")
67		return
68	}
69
70	result.oc, err = client.ListResponder(resp)
71	if err != nil {
72		err = autorest.NewErrorWithError(err, "media.OperationsClient", "List", resp, "Failure responding to request")
73	}
74
75	return
76}
77
78// ListPreparer prepares the List request.
79func (client OperationsClient) ListPreparer(ctx context.Context) (*http.Request, error) {
80	const APIVersion = "2018-03-30-preview"
81	queryParameters := map[string]interface{}{
82		"api-version": APIVersion,
83	}
84
85	preparer := autorest.CreatePreparer(
86		autorest.AsGet(),
87		autorest.WithBaseURL(client.BaseURI),
88		autorest.WithPath("/providers/Microsoft.Media/operations"),
89		autorest.WithQueryParameters(queryParameters))
90	return preparer.Prepare((&http.Request{}).WithContext(ctx))
91}
92
93// ListSender sends the List request. The method will close the
94// http.Response Body if it receives an error.
95func (client OperationsClient) ListSender(req *http.Request) (*http.Response, error) {
96	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
97}
98
99// ListResponder handles the response to the List request. The method always
100// closes the http.Response Body.
101func (client OperationsClient) ListResponder(resp *http.Response) (result OperationCollection, err error) {
102	err = autorest.Respond(
103		resp,
104		client.ByInspecting(),
105		azure.WithErrorUnlessStatusCode(http.StatusOK),
106		autorest.ByUnmarshallingJSON(&result),
107		autorest.ByClosing())
108	result.Response = autorest.Response{Response: resp}
109	return
110}
111
112// listNextResults retrieves the next set of results, if any.
113func (client OperationsClient) listNextResults(ctx context.Context, lastResults OperationCollection) (result OperationCollection, err error) {
114	req, err := lastResults.operationCollectionPreparer(ctx)
115	if err != nil {
116		return result, autorest.NewErrorWithError(err, "media.OperationsClient", "listNextResults", nil, "Failure preparing next results request")
117	}
118	if req == nil {
119		return
120	}
121	resp, err := client.ListSender(req)
122	if err != nil {
123		result.Response = autorest.Response{Response: resp}
124		return result, autorest.NewErrorWithError(err, "media.OperationsClient", "listNextResults", resp, "Failure sending next results request")
125	}
126	result, err = client.ListResponder(resp)
127	if err != nil {
128		err = autorest.NewErrorWithError(err, "media.OperationsClient", "listNextResults", resp, "Failure responding to next results request")
129	}
130	return
131}
132
133// ListComplete enumerates all values, automatically crossing page boundaries as required.
134func (client OperationsClient) ListComplete(ctx context.Context) (result OperationCollectionIterator, err error) {
135	if tracing.IsEnabled() {
136		ctx = tracing.StartSpan(ctx, fqdn+"/OperationsClient.List")
137		defer func() {
138			sc := -1
139			if result.Response().Response.Response != nil {
140				sc = result.page.Response().Response.Response.StatusCode
141			}
142			tracing.EndSpan(ctx, sc, err)
143		}()
144	}
145	result.page, err = client.List(ctx)
146	return
147}
148