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// LocationsClient is the client for the Locations methods of the Media service.
29type LocationsClient struct {
30	BaseClient
31}
32
33// NewLocationsClient creates an instance of the LocationsClient client.
34func NewLocationsClient(subscriptionID string) LocationsClient {
35	return NewLocationsClientWithBaseURI(DefaultBaseURI, subscriptionID)
36}
37
38// NewLocationsClientWithBaseURI creates an instance of the LocationsClient client.
39func NewLocationsClientWithBaseURI(baseURI string, subscriptionID string) LocationsClient {
40	return LocationsClient{NewWithBaseURI(baseURI, subscriptionID)}
41}
42
43// CheckNameAvailability checks whether the Media Service resource name is available.
44// Parameters:
45// parameters - the request parameters
46func (client LocationsClient) CheckNameAvailability(ctx context.Context, locationName string, parameters CheckNameAvailabilityInput) (result EntityNameAvailabilityCheckOutput, err error) {
47	if tracing.IsEnabled() {
48		ctx = tracing.StartSpan(ctx, fqdn+"/LocationsClient.CheckNameAvailability")
49		defer func() {
50			sc := -1
51			if result.Response.Response != nil {
52				sc = result.Response.Response.StatusCode
53			}
54			tracing.EndSpan(ctx, sc, err)
55		}()
56	}
57	req, err := client.CheckNameAvailabilityPreparer(ctx, locationName, parameters)
58	if err != nil {
59		err = autorest.NewErrorWithError(err, "media.LocationsClient", "CheckNameAvailability", nil, "Failure preparing request")
60		return
61	}
62
63	resp, err := client.CheckNameAvailabilitySender(req)
64	if err != nil {
65		result.Response = autorest.Response{Response: resp}
66		err = autorest.NewErrorWithError(err, "media.LocationsClient", "CheckNameAvailability", resp, "Failure sending request")
67		return
68	}
69
70	result, err = client.CheckNameAvailabilityResponder(resp)
71	if err != nil {
72		err = autorest.NewErrorWithError(err, "media.LocationsClient", "CheckNameAvailability", resp, "Failure responding to request")
73	}
74
75	return
76}
77
78// CheckNameAvailabilityPreparer prepares the CheckNameAvailability request.
79func (client LocationsClient) CheckNameAvailabilityPreparer(ctx context.Context, locationName string, parameters CheckNameAvailabilityInput) (*http.Request, error) {
80	pathParameters := map[string]interface{}{
81		"locationName":   autorest.Encode("path", locationName),
82		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
83	}
84
85	const APIVersion = "2018-03-30-preview"
86	queryParameters := map[string]interface{}{
87		"api-version": APIVersion,
88	}
89
90	preparer := autorest.CreatePreparer(
91		autorest.AsContentType("application/json; charset=utf-8"),
92		autorest.AsPost(),
93		autorest.WithBaseURL(client.BaseURI),
94		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Media/locations/{locationName}/checkNameAvailability", pathParameters),
95		autorest.WithJSON(parameters),
96		autorest.WithQueryParameters(queryParameters))
97	return preparer.Prepare((&http.Request{}).WithContext(ctx))
98}
99
100// CheckNameAvailabilitySender sends the CheckNameAvailability request. The method will close the
101// http.Response Body if it receives an error.
102func (client LocationsClient) CheckNameAvailabilitySender(req *http.Request) (*http.Response, error) {
103	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
104	return autorest.SendWithSender(client, req, sd...)
105}
106
107// CheckNameAvailabilityResponder handles the response to the CheckNameAvailability request. The method always
108// closes the http.Response Body.
109func (client LocationsClient) CheckNameAvailabilityResponder(resp *http.Response) (result EntityNameAvailabilityCheckOutput, err error) {
110	err = autorest.Respond(
111		resp,
112		client.ByInspecting(),
113		azure.WithErrorUnlessStatusCode(http.StatusOK),
114		autorest.ByUnmarshallingJSON(&result),
115		autorest.ByClosing())
116	result.Response = autorest.Response{Response: resp}
117	return
118}
119