1package blockchain
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 REST API for Azure Blockchain 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.
39func NewOperationsClientWithBaseURI(baseURI string, subscriptionID string) OperationsClient {
40	return OperationsClient{NewWithBaseURI(baseURI, subscriptionID)}
41}
42
43// List lists the available operations of Microsoft.Blockchain resource provider.
44func (client OperationsClient) List(ctx context.Context) (result ResourceProviderOperationCollectionPage, err error) {
45	if tracing.IsEnabled() {
46		ctx = tracing.StartSpan(ctx, fqdn+"/OperationsClient.List")
47		defer func() {
48			sc := -1
49			if result.rpoc.Response.Response != nil {
50				sc = result.rpoc.Response.Response.StatusCode
51			}
52			tracing.EndSpan(ctx, sc, err)
53		}()
54	}
55	result.fn = client.listNextResults
56	req, err := client.ListPreparer(ctx)
57	if err != nil {
58		err = autorest.NewErrorWithError(err, "blockchain.OperationsClient", "List", nil, "Failure preparing request")
59		return
60	}
61
62	resp, err := client.ListSender(req)
63	if err != nil {
64		result.rpoc.Response = autorest.Response{Response: resp}
65		err = autorest.NewErrorWithError(err, "blockchain.OperationsClient", "List", resp, "Failure sending request")
66		return
67	}
68
69	result.rpoc, err = client.ListResponder(resp)
70	if err != nil {
71		err = autorest.NewErrorWithError(err, "blockchain.OperationsClient", "List", resp, "Failure responding to request")
72	}
73
74	return
75}
76
77// ListPreparer prepares the List request.
78func (client OperationsClient) ListPreparer(ctx context.Context) (*http.Request, error) {
79	const APIVersion = "2018-06-01-preview"
80	queryParameters := map[string]interface{}{
81		"api-version": APIVersion,
82	}
83
84	preparer := autorest.CreatePreparer(
85		autorest.AsGet(),
86		autorest.WithBaseURL(client.BaseURI),
87		autorest.WithPath("/providers/Microsoft.Blockchain/operations"),
88		autorest.WithQueryParameters(queryParameters))
89	return preparer.Prepare((&http.Request{}).WithContext(ctx))
90}
91
92// ListSender sends the List request. The method will close the
93// http.Response Body if it receives an error.
94func (client OperationsClient) ListSender(req *http.Request) (*http.Response, error) {
95	sd := autorest.GetSendDecorators(req.Context(), autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
96	return autorest.SendWithSender(client, req, sd...)
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 ResourceProviderOperationCollection, 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 ResourceProviderOperationCollection) (result ResourceProviderOperationCollection, err error) {
114	req, err := lastResults.resourceProviderOperationCollectionPreparer(ctx)
115	if err != nil {
116		return result, autorest.NewErrorWithError(err, "blockchain.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, "blockchain.OperationsClient", "listNextResults", resp, "Failure sending next results request")
125	}
126	result, err = client.ListResponder(resp)
127	if err != nil {
128		err = autorest.NewErrorWithError(err, "blockchain.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 ResourceProviderOperationCollectionIterator, 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