1package apimanagement
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/autorest/validation"
25	"github.com/Azure/go-autorest/tracing"
26	"net/http"
27)
28
29// ContentTypesClient is the apiManagement Client
30type ContentTypesClient struct {
31	BaseClient
32}
33
34// NewContentTypesClient creates an instance of the ContentTypesClient client.
35func NewContentTypesClient(subscriptionID string) ContentTypesClient {
36	return NewContentTypesClientWithBaseURI(DefaultBaseURI, subscriptionID)
37}
38
39// NewContentTypesClientWithBaseURI creates an instance of the ContentTypesClient client using a custom endpoint.  Use
40// this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
41func NewContentTypesClientWithBaseURI(baseURI string, subscriptionID string) ContentTypesClient {
42	return ContentTypesClient{NewWithBaseURI(baseURI, subscriptionID)}
43}
44
45// Get gets API Management content type details
46// Parameters:
47// resourceGroupName - the name of the resource group.
48// serviceName - the name of the API Management service.
49// contentTypeID - content type identifier.
50func (client ContentTypesClient) Get(ctx context.Context, resourceGroupName string, serviceName string, contentTypeID string) (result ContentTypeContract, err error) {
51	if tracing.IsEnabled() {
52		ctx = tracing.StartSpan(ctx, fqdn+"/ContentTypesClient.Get")
53		defer func() {
54			sc := -1
55			if result.Response.Response != nil {
56				sc = result.Response.Response.StatusCode
57			}
58			tracing.EndSpan(ctx, sc, err)
59		}()
60	}
61	if err := validation.Validate([]validation.Validation{
62		{TargetValue: serviceName,
63			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
64				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
65				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
66		{TargetValue: contentTypeID,
67			Constraints: []validation.Constraint{{Target: "contentTypeID", Name: validation.MaxLength, Rule: 80, Chain: nil},
68				{Target: "contentTypeID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
69		return result, validation.NewError("apimanagement.ContentTypesClient", "Get", err.Error())
70	}
71
72	req, err := client.GetPreparer(ctx, resourceGroupName, serviceName, contentTypeID)
73	if err != nil {
74		err = autorest.NewErrorWithError(err, "apimanagement.ContentTypesClient", "Get", nil, "Failure preparing request")
75		return
76	}
77
78	resp, err := client.GetSender(req)
79	if err != nil {
80		result.Response = autorest.Response{Response: resp}
81		err = autorest.NewErrorWithError(err, "apimanagement.ContentTypesClient", "Get", resp, "Failure sending request")
82		return
83	}
84
85	result, err = client.GetResponder(resp)
86	if err != nil {
87		err = autorest.NewErrorWithError(err, "apimanagement.ContentTypesClient", "Get", resp, "Failure responding to request")
88		return
89	}
90
91	return
92}
93
94// GetPreparer prepares the Get request.
95func (client ContentTypesClient) GetPreparer(ctx context.Context, resourceGroupName string, serviceName string, contentTypeID string) (*http.Request, error) {
96	pathParameters := map[string]interface{}{
97		"contentTypeId":     autorest.Encode("path", contentTypeID),
98		"resourceGroupName": autorest.Encode("path", resourceGroupName),
99		"serviceName":       autorest.Encode("path", serviceName),
100		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
101	}
102
103	const APIVersion = "2019-12-01"
104	queryParameters := map[string]interface{}{
105		"api-version": APIVersion,
106	}
107
108	preparer := autorest.CreatePreparer(
109		autorest.AsGet(),
110		autorest.WithBaseURL(client.BaseURI),
111		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/contentTypes/{contentTypeId}", pathParameters),
112		autorest.WithQueryParameters(queryParameters))
113	return preparer.Prepare((&http.Request{}).WithContext(ctx))
114}
115
116// GetSender sends the Get request. The method will close the
117// http.Response Body if it receives an error.
118func (client ContentTypesClient) GetSender(req *http.Request) (*http.Response, error) {
119	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
120}
121
122// GetResponder handles the response to the Get request. The method always
123// closes the http.Response Body.
124func (client ContentTypesClient) GetResponder(resp *http.Response) (result ContentTypeContract, err error) {
125	err = autorest.Respond(
126		resp,
127		azure.WithErrorUnlessStatusCode(http.StatusOK),
128		autorest.ByUnmarshallingJSON(&result),
129		autorest.ByClosing())
130	result.Response = autorest.Response{Response: resp}
131	return
132}
133