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