1package billing
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// PropertyClient is the billing client provides access to billing resources for Azure subscriptions.
29type PropertyClient struct {
30	BaseClient
31}
32
33// NewPropertyClient creates an instance of the PropertyClient client.
34func NewPropertyClient(subscriptionID string) PropertyClient {
35	return NewPropertyClientWithBaseURI(DefaultBaseURI, subscriptionID)
36}
37
38// NewPropertyClientWithBaseURI creates an instance of the PropertyClient client using a custom endpoint.  Use this
39// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
40func NewPropertyClientWithBaseURI(baseURI string, subscriptionID string) PropertyClient {
41	return PropertyClient{NewWithBaseURI(baseURI, subscriptionID)}
42}
43
44// Get get billing property by subscription Id.
45func (client PropertyClient) Get(ctx context.Context) (result Property, err error) {
46	if tracing.IsEnabled() {
47		ctx = tracing.StartSpan(ctx, fqdn+"/PropertyClient.Get")
48		defer func() {
49			sc := -1
50			if result.Response.Response != nil {
51				sc = result.Response.Response.StatusCode
52			}
53			tracing.EndSpan(ctx, sc, err)
54		}()
55	}
56	req, err := client.GetPreparer(ctx)
57	if err != nil {
58		err = autorest.NewErrorWithError(err, "billing.PropertyClient", "Get", nil, "Failure preparing request")
59		return
60	}
61
62	resp, err := client.GetSender(req)
63	if err != nil {
64		result.Response = autorest.Response{Response: resp}
65		err = autorest.NewErrorWithError(err, "billing.PropertyClient", "Get", resp, "Failure sending request")
66		return
67	}
68
69	result, err = client.GetResponder(resp)
70	if err != nil {
71		err = autorest.NewErrorWithError(err, "billing.PropertyClient", "Get", resp, "Failure responding to request")
72	}
73
74	return
75}
76
77// GetPreparer prepares the Get request.
78func (client PropertyClient) GetPreparer(ctx context.Context) (*http.Request, error) {
79	pathParameters := map[string]interface{}{
80		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
81	}
82
83	const APIVersion = "2018-11-01-preview"
84	queryParameters := map[string]interface{}{
85		"api-version": APIVersion,
86	}
87
88	preparer := autorest.CreatePreparer(
89		autorest.AsGet(),
90		autorest.WithBaseURL(client.BaseURI),
91		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Billing/billingProperty", pathParameters),
92		autorest.WithQueryParameters(queryParameters))
93	return preparer.Prepare((&http.Request{}).WithContext(ctx))
94}
95
96// GetSender sends the Get request. The method will close the
97// http.Response Body if it receives an error.
98func (client PropertyClient) GetSender(req *http.Request) (*http.Response, error) {
99	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
100}
101
102// GetResponder handles the response to the Get request. The method always
103// closes the http.Response Body.
104func (client PropertyClient) GetResponder(resp *http.Response) (result Property, err error) {
105	err = autorest.Respond(
106		resp,
107		client.ByInspecting(),
108		azure.WithErrorUnlessStatusCode(http.StatusOK),
109		autorest.ByUnmarshallingJSON(&result),
110		autorest.ByClosing())
111	result.Response = autorest.Response{Response: resp}
112	return
113}
114