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// LocationsClient is the REST API for Azure Blockchain Service
18type LocationsClient struct {
19	BaseClient
20}
21
22// NewLocationsClient creates an instance of the LocationsClient client.
23func NewLocationsClient(subscriptionID string) LocationsClient {
24	return NewLocationsClientWithBaseURI(DefaultBaseURI, subscriptionID)
25}
26
27// NewLocationsClientWithBaseURI creates an instance of the LocationsClient 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 NewLocationsClientWithBaseURI(baseURI string, subscriptionID string) LocationsClient {
30	return LocationsClient{NewWithBaseURI(baseURI, subscriptionID)}
31}
32
33// CheckNameAvailability to check whether a resource name is available.
34// Parameters:
35// locationName - location Name.
36// nameAvailabilityRequest - name availability request payload.
37func (client LocationsClient) CheckNameAvailability(ctx context.Context, locationName string, nameAvailabilityRequest *NameAvailabilityRequest) (result NameAvailability, err error) {
38	if tracing.IsEnabled() {
39		ctx = tracing.StartSpan(ctx, fqdn+"/LocationsClient.CheckNameAvailability")
40		defer func() {
41			sc := -1
42			if result.Response.Response != nil {
43				sc = result.Response.Response.StatusCode
44			}
45			tracing.EndSpan(ctx, sc, err)
46		}()
47	}
48	req, err := client.CheckNameAvailabilityPreparer(ctx, locationName, nameAvailabilityRequest)
49	if err != nil {
50		err = autorest.NewErrorWithError(err, "blockchain.LocationsClient", "CheckNameAvailability", nil, "Failure preparing request")
51		return
52	}
53
54	resp, err := client.CheckNameAvailabilitySender(req)
55	if err != nil {
56		result.Response = autorest.Response{Response: resp}
57		err = autorest.NewErrorWithError(err, "blockchain.LocationsClient", "CheckNameAvailability", resp, "Failure sending request")
58		return
59	}
60
61	result, err = client.CheckNameAvailabilityResponder(resp)
62	if err != nil {
63		err = autorest.NewErrorWithError(err, "blockchain.LocationsClient", "CheckNameAvailability", resp, "Failure responding to request")
64		return
65	}
66
67	return
68}
69
70// CheckNameAvailabilityPreparer prepares the CheckNameAvailability request.
71func (client LocationsClient) CheckNameAvailabilityPreparer(ctx context.Context, locationName string, nameAvailabilityRequest *NameAvailabilityRequest) (*http.Request, error) {
72	pathParameters := map[string]interface{}{
73		"locationName":   autorest.Encode("path", locationName),
74		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
75	}
76
77	const APIVersion = "2018-06-01-preview"
78	queryParameters := map[string]interface{}{
79		"api-version": APIVersion,
80	}
81
82	preparer := autorest.CreatePreparer(
83		autorest.AsContentType("application/json; charset=utf-8"),
84		autorest.AsPost(),
85		autorest.WithBaseURL(client.BaseURI),
86		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Blockchain/locations/{locationName}/checkNameAvailability", pathParameters),
87		autorest.WithQueryParameters(queryParameters))
88	if nameAvailabilityRequest != nil {
89		preparer = autorest.DecoratePreparer(preparer,
90			autorest.WithJSON(nameAvailabilityRequest))
91	}
92	return preparer.Prepare((&http.Request{}).WithContext(ctx))
93}
94
95// CheckNameAvailabilitySender sends the CheckNameAvailability request. The method will close the
96// http.Response Body if it receives an error.
97func (client LocationsClient) CheckNameAvailabilitySender(req *http.Request) (*http.Response, error) {
98	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
99}
100
101// CheckNameAvailabilityResponder handles the response to the CheckNameAvailability request. The method always
102// closes the http.Response Body.
103func (client LocationsClient) CheckNameAvailabilityResponder(resp *http.Response) (result NameAvailability, err error) {
104	err = autorest.Respond(
105		resp,
106		azure.WithErrorUnlessStatusCode(http.StatusOK),
107		autorest.ByUnmarshallingJSON(&result),
108		autorest.ByClosing())
109	result.Response = autorest.Response{Response: resp}
110	return
111}
112
113// ListConsortiums lists the available consortiums for a subscription.
114// Parameters:
115// locationName - location Name.
116func (client LocationsClient) ListConsortiums(ctx context.Context, locationName string) (result ConsortiumCollection, err error) {
117	if tracing.IsEnabled() {
118		ctx = tracing.StartSpan(ctx, fqdn+"/LocationsClient.ListConsortiums")
119		defer func() {
120			sc := -1
121			if result.Response.Response != nil {
122				sc = result.Response.Response.StatusCode
123			}
124			tracing.EndSpan(ctx, sc, err)
125		}()
126	}
127	req, err := client.ListConsortiumsPreparer(ctx, locationName)
128	if err != nil {
129		err = autorest.NewErrorWithError(err, "blockchain.LocationsClient", "ListConsortiums", nil, "Failure preparing request")
130		return
131	}
132
133	resp, err := client.ListConsortiumsSender(req)
134	if err != nil {
135		result.Response = autorest.Response{Response: resp}
136		err = autorest.NewErrorWithError(err, "blockchain.LocationsClient", "ListConsortiums", resp, "Failure sending request")
137		return
138	}
139
140	result, err = client.ListConsortiumsResponder(resp)
141	if err != nil {
142		err = autorest.NewErrorWithError(err, "blockchain.LocationsClient", "ListConsortiums", resp, "Failure responding to request")
143		return
144	}
145
146	return
147}
148
149// ListConsortiumsPreparer prepares the ListConsortiums request.
150func (client LocationsClient) ListConsortiumsPreparer(ctx context.Context, locationName string) (*http.Request, error) {
151	pathParameters := map[string]interface{}{
152		"locationName":   autorest.Encode("path", locationName),
153		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
154	}
155
156	const APIVersion = "2018-06-01-preview"
157	queryParameters := map[string]interface{}{
158		"api-version": APIVersion,
159	}
160
161	preparer := autorest.CreatePreparer(
162		autorest.AsPost(),
163		autorest.WithBaseURL(client.BaseURI),
164		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Blockchain/locations/{locationName}/listConsortiums", pathParameters),
165		autorest.WithQueryParameters(queryParameters))
166	return preparer.Prepare((&http.Request{}).WithContext(ctx))
167}
168
169// ListConsortiumsSender sends the ListConsortiums request. The method will close the
170// http.Response Body if it receives an error.
171func (client LocationsClient) ListConsortiumsSender(req *http.Request) (*http.Response, error) {
172	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
173}
174
175// ListConsortiumsResponder handles the response to the ListConsortiums request. The method always
176// closes the http.Response Body.
177func (client LocationsClient) ListConsortiumsResponder(resp *http.Response) (result ConsortiumCollection, err error) {
178	err = autorest.Respond(
179		resp,
180		azure.WithErrorUnlessStatusCode(http.StatusOK),
181		autorest.ByUnmarshallingJSON(&result),
182		autorest.ByClosing())
183	result.Response = autorest.Response{Response: resp}
184	return
185}
186