1package commitmentplans
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// SkusClient is the these APIs allow end users to operate on Azure Machine Learning Commitment Plans resources and
18// their child Commitment Association resources. They support CRUD operations for commitment plans, get and list
19// operations for commitment associations, moving commitment associations between commitment plans, and retrieving
20// commitment plan usage history.
21type SkusClient struct {
22	BaseClient
23}
24
25// NewSkusClient creates an instance of the SkusClient client.
26func NewSkusClient(subscriptionID string) SkusClient {
27	return NewSkusClientWithBaseURI(DefaultBaseURI, subscriptionID)
28}
29
30// NewSkusClientWithBaseURI creates an instance of the SkusClient client using a custom endpoint.  Use this when
31// interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
32func NewSkusClientWithBaseURI(baseURI string, subscriptionID string) SkusClient {
33	return SkusClient{NewWithBaseURI(baseURI, subscriptionID)}
34}
35
36// List lists the available commitment plan SKUs.
37func (client SkusClient) List(ctx context.Context) (result SkuListResult, err error) {
38	if tracing.IsEnabled() {
39		ctx = tracing.StartSpan(ctx, fqdn+"/SkusClient.List")
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.ListPreparer(ctx)
49	if err != nil {
50		err = autorest.NewErrorWithError(err, "commitmentplans.SkusClient", "List", nil, "Failure preparing request")
51		return
52	}
53
54	resp, err := client.ListSender(req)
55	if err != nil {
56		result.Response = autorest.Response{Response: resp}
57		err = autorest.NewErrorWithError(err, "commitmentplans.SkusClient", "List", resp, "Failure sending request")
58		return
59	}
60
61	result, err = client.ListResponder(resp)
62	if err != nil {
63		err = autorest.NewErrorWithError(err, "commitmentplans.SkusClient", "List", resp, "Failure responding to request")
64		return
65	}
66
67	return
68}
69
70// ListPreparer prepares the List request.
71func (client SkusClient) ListPreparer(ctx context.Context) (*http.Request, error) {
72	pathParameters := map[string]interface{}{
73		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
74	}
75
76	const APIVersion = "2016-05-01-preview"
77	queryParameters := map[string]interface{}{
78		"api-version": APIVersion,
79	}
80
81	preparer := autorest.CreatePreparer(
82		autorest.AsGet(),
83		autorest.WithBaseURL(client.BaseURI),
84		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.MachineLearning/skus", pathParameters),
85		autorest.WithQueryParameters(queryParameters))
86	return preparer.Prepare((&http.Request{}).WithContext(ctx))
87}
88
89// ListSender sends the List request. The method will close the
90// http.Response Body if it receives an error.
91func (client SkusClient) ListSender(req *http.Request) (*http.Response, error) {
92	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
93}
94
95// ListResponder handles the response to the List request. The method always
96// closes the http.Response Body.
97func (client SkusClient) ListResponder(resp *http.Response) (result SkuListResult, err error) {
98	err = autorest.Respond(
99		resp,
100		azure.WithErrorUnlessStatusCode(http.StatusOK),
101		autorest.ByUnmarshallingJSON(&result),
102		autorest.ByClosing())
103	result.Response = autorest.Response{Response: resp}
104	return
105}
106