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