...

Source file src/github.com/Azure/azure-sdk-for-go/services/consumption/mgmt/2018-03-31/consumption/getbalancesbybillingaccount.go

Documentation: github.com/Azure/azure-sdk-for-go/services/consumption/mgmt/2018-03-31/consumption

     1  package consumption
     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  
     9  import (
    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  // GetBalancesByBillingAccountClient is the consumption management client provides access to consumption resources for
    18  // Azure Enterprise Subscriptions.
    19  type GetBalancesByBillingAccountClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewGetBalancesByBillingAccountClient creates an instance of the GetBalancesByBillingAccountClient client.
    24  func NewGetBalancesByBillingAccountClient(subscriptionID string) GetBalancesByBillingAccountClient {
    25  	return NewGetBalancesByBillingAccountClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewGetBalancesByBillingAccountClientWithBaseURI creates an instance of the GetBalancesByBillingAccountClient client
    29  // using a custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign
    30  // clouds, Azure stack).
    31  func NewGetBalancesByBillingAccountClientWithBaseURI(baseURI string, subscriptionID string) GetBalancesByBillingAccountClient {
    32  	return GetBalancesByBillingAccountClient{NewWithBaseURI(baseURI, subscriptionID)}
    33  }
    34  
    35  // ByBillingPeriod gets the balances for a scope by billing period and billingAccountId. Balances are available via
    36  // this API only for May 1, 2014 or later.
    37  // Parameters:
    38  // billingAccountID - billingAccount ID
    39  // billingPeriodName - billing Period Name.
    40  func (client GetBalancesByBillingAccountClient) ByBillingPeriod(ctx context.Context, billingAccountID string, billingPeriodName string) (result Balance, err error) {
    41  	if tracing.IsEnabled() {
    42  		ctx = tracing.StartSpan(ctx, fqdn+"/GetBalancesByBillingAccountClient.ByBillingPeriod")
    43  		defer func() {
    44  			sc := -1
    45  			if result.Response.Response != nil {
    46  				sc = result.Response.Response.StatusCode
    47  			}
    48  			tracing.EndSpan(ctx, sc, err)
    49  		}()
    50  	}
    51  	req, err := client.ByBillingPeriodPreparer(ctx, billingAccountID, billingPeriodName)
    52  	if err != nil {
    53  		err = autorest.NewErrorWithError(err, "consumption.GetBalancesByBillingAccountClient", "ByBillingPeriod", nil, "Failure preparing request")
    54  		return
    55  	}
    56  
    57  	resp, err := client.ByBillingPeriodSender(req)
    58  	if err != nil {
    59  		result.Response = autorest.Response{Response: resp}
    60  		err = autorest.NewErrorWithError(err, "consumption.GetBalancesByBillingAccountClient", "ByBillingPeriod", resp, "Failure sending request")
    61  		return
    62  	}
    63  
    64  	result, err = client.ByBillingPeriodResponder(resp)
    65  	if err != nil {
    66  		err = autorest.NewErrorWithError(err, "consumption.GetBalancesByBillingAccountClient", "ByBillingPeriod", resp, "Failure responding to request")
    67  		return
    68  	}
    69  
    70  	return
    71  }
    72  
    73  // ByBillingPeriodPreparer prepares the ByBillingPeriod request.
    74  func (client GetBalancesByBillingAccountClient) ByBillingPeriodPreparer(ctx context.Context, billingAccountID string, billingPeriodName string) (*http.Request, error) {
    75  	pathParameters := map[string]interface{}{
    76  		"billingAccountId":  autorest.Encode("path", billingAccountID),
    77  		"billingPeriodName": autorest.Encode("path", billingPeriodName),
    78  	}
    79  
    80  	const APIVersion = "2018-03-31"
    81  	queryParameters := map[string]interface{}{
    82  		"api-version": APIVersion,
    83  	}
    84  
    85  	preparer := autorest.CreatePreparer(
    86  		autorest.AsGet(),
    87  		autorest.WithBaseURL(client.BaseURI),
    88  		autorest.WithPathParameters("/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/providers/Microsoft.Billing/billingPeriods/{billingPeriodName}/providers/Microsoft.Consumption/balances", pathParameters),
    89  		autorest.WithQueryParameters(queryParameters))
    90  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    91  }
    92  
    93  // ByBillingPeriodSender sends the ByBillingPeriod request. The method will close the
    94  // http.Response Body if it receives an error.
    95  func (client GetBalancesByBillingAccountClient) ByBillingPeriodSender(req *http.Request) (*http.Response, error) {
    96  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
    97  }
    98  
    99  // ByBillingPeriodResponder handles the response to the ByBillingPeriod request. The method always
   100  // closes the http.Response Body.
   101  func (client GetBalancesByBillingAccountClient) ByBillingPeriodResponder(resp *http.Response) (result Balance, err error) {
   102  	err = autorest.Respond(
   103  		resp,
   104  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   105  		autorest.ByUnmarshallingJSON(&result),
   106  		autorest.ByClosing())
   107  	result.Response = autorest.Response{Response: resp}
   108  	return
   109  }
   110  

View as plain text