1package apimanagement
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/autorest/validation"
14	"github.com/Azure/go-autorest/tracing"
15	"net/http"
16)
17
18// APIExportClient is the client for the APIExport methods of the Apimanagement service.
19type APIExportClient struct {
20	BaseClient
21}
22
23// NewAPIExportClient creates an instance of the APIExportClient client.
24func NewAPIExportClient() APIExportClient {
25	return APIExportClient{New()}
26}
27
28// Get gets the details of the API specified by its identifier in the format specified to the Storage Blob with SAS Key
29// valid for 5 minutes.
30// Parameters:
31// apimBaseURL - the management endpoint of the API Management service, for example
32// https://myapimservice.management.azure-api.net.
33// apiid - API identifier. Must be unique in the current API Management service instance.
34func (client APIExportClient) Get(ctx context.Context, apimBaseURL string, apiid string) (result APIExportResult, err error) {
35	if tracing.IsEnabled() {
36		ctx = tracing.StartSpan(ctx, fqdn+"/APIExportClient.Get")
37		defer func() {
38			sc := -1
39			if result.Response.Response != nil {
40				sc = result.Response.Response.StatusCode
41			}
42			tracing.EndSpan(ctx, sc, err)
43		}()
44	}
45	if err := validation.Validate([]validation.Validation{
46		{TargetValue: apiid,
47			Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 256, Chain: nil},
48				{Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil},
49				{Target: "apiid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
50		return result, validation.NewError("apimanagement.APIExportClient", "Get", err.Error())
51	}
52
53	req, err := client.GetPreparer(ctx, apimBaseURL, apiid)
54	if err != nil {
55		err = autorest.NewErrorWithError(err, "apimanagement.APIExportClient", "Get", nil, "Failure preparing request")
56		return
57	}
58
59	resp, err := client.GetSender(req)
60	if err != nil {
61		result.Response = autorest.Response{Response: resp}
62		err = autorest.NewErrorWithError(err, "apimanagement.APIExportClient", "Get", resp, "Failure sending request")
63		return
64	}
65
66	result, err = client.GetResponder(resp)
67	if err != nil {
68		err = autorest.NewErrorWithError(err, "apimanagement.APIExportClient", "Get", resp, "Failure responding to request")
69		return
70	}
71
72	return
73}
74
75// GetPreparer prepares the Get request.
76func (client APIExportClient) GetPreparer(ctx context.Context, apimBaseURL string, apiid string) (*http.Request, error) {
77	urlParameters := map[string]interface{}{
78		"apimBaseUrl": apimBaseURL,
79	}
80
81	pathParameters := map[string]interface{}{
82		"apiId": autorest.Encode("path", apiid),
83	}
84
85	const APIVersion = "2017-03-01"
86	queryParameters := map[string]interface{}{
87		"api-version": APIVersion,
88		"export":      autorest.Encode("query", "true"),
89	}
90
91	preparer := autorest.CreatePreparer(
92		autorest.AsGet(),
93		autorest.WithCustomBaseURL("{apimBaseUrl}", urlParameters),
94		autorest.WithPathParameters("/apis/{apiId}", pathParameters),
95		autorest.WithQueryParameters(queryParameters))
96	return preparer.Prepare((&http.Request{}).WithContext(ctx))
97}
98
99// GetSender sends the Get request. The method will close the
100// http.Response Body if it receives an error.
101func (client APIExportClient) GetSender(req *http.Request) (*http.Response, error) {
102	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
103}
104
105// GetResponder handles the response to the Get request. The method always
106// closes the http.Response Body.
107func (client APIExportClient) GetResponder(resp *http.Response) (result APIExportResult, err error) {
108	err = autorest.Respond(
109		resp,
110		azure.WithErrorUnlessStatusCode(http.StatusOK),
111		autorest.ByUnmarshallingJSON(&result),
112		autorest.ByClosing())
113	result.Response = autorest.Response{Response: resp}
114	return
115}
116