1 package consumption
2
3
4
5
6
7
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
18
19 type GetBalancesByBillingAccountClient struct {
20 BaseClient
21 }
22
23
24 func NewGetBalancesByBillingAccountClient(subscriptionID string) GetBalancesByBillingAccountClient {
25 return NewGetBalancesByBillingAccountClientWithBaseURI(DefaultBaseURI, subscriptionID)
26 }
27
28
29
30
31 func NewGetBalancesByBillingAccountClientWithBaseURI(baseURI string, subscriptionID string) GetBalancesByBillingAccountClient {
32 return GetBalancesByBillingAccountClient{NewWithBaseURI(baseURI, subscriptionID)}
33 }
34
35
36
37
38
39
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
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
94
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
100
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