1package apimanagement 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// QuotaByPeriodKeysClient is the client for the QuotaByPeriodKeys methods of the Apimanagement service. 29type QuotaByPeriodKeysClient struct { 30 BaseClient 31} 32 33// NewQuotaByPeriodKeysClient creates an instance of the QuotaByPeriodKeysClient client. 34func NewQuotaByPeriodKeysClient() QuotaByPeriodKeysClient { 35 return QuotaByPeriodKeysClient{New()} 36} 37 38// Get gets the value of the quota counter associated with the counter-key in the policy for the specific period in 39// service instance. 40// Parameters: 41// apimBaseURL - the management endpoint of the API Management service, for example 42// https://myapimservice.management.azure-api.net. 43// quotaCounterKey - quota counter key identifier.This is the result of expression defined in counter-key 44// attribute of the quota-by-key policy.For Example, if you specify counter-key="boo" in the policy, then it’s 45// accessible by "boo" counter key. But if it’s defined as counter-key="@("b"+"a")" then it will be accessible 46// by "ba" key 47// quotaPeriodKey - quota period key identifier. 48func (client QuotaByPeriodKeysClient) Get(ctx context.Context, apimBaseURL string, quotaCounterKey string, quotaPeriodKey string) (result QuotaCounterContract, err error) { 49 if tracing.IsEnabled() { 50 ctx = tracing.StartSpan(ctx, fqdn+"/QuotaByPeriodKeysClient.Get") 51 defer func() { 52 sc := -1 53 if result.Response.Response != nil { 54 sc = result.Response.Response.StatusCode 55 } 56 tracing.EndSpan(ctx, sc, err) 57 }() 58 } 59 req, err := client.GetPreparer(ctx, apimBaseURL, quotaCounterKey, quotaPeriodKey) 60 if err != nil { 61 err = autorest.NewErrorWithError(err, "apimanagement.QuotaByPeriodKeysClient", "Get", nil, "Failure preparing request") 62 return 63 } 64 65 resp, err := client.GetSender(req) 66 if err != nil { 67 result.Response = autorest.Response{Response: resp} 68 err = autorest.NewErrorWithError(err, "apimanagement.QuotaByPeriodKeysClient", "Get", resp, "Failure sending request") 69 return 70 } 71 72 result, err = client.GetResponder(resp) 73 if err != nil { 74 err = autorest.NewErrorWithError(err, "apimanagement.QuotaByPeriodKeysClient", "Get", resp, "Failure responding to request") 75 } 76 77 return 78} 79 80// GetPreparer prepares the Get request. 81func (client QuotaByPeriodKeysClient) GetPreparer(ctx context.Context, apimBaseURL string, quotaCounterKey string, quotaPeriodKey string) (*http.Request, error) { 82 urlParameters := map[string]interface{}{ 83 "apimBaseUrl": apimBaseURL, 84 } 85 86 pathParameters := map[string]interface{}{ 87 "quotaCounterKey": autorest.Encode("path", quotaCounterKey), 88 "quotaPeriodKey": autorest.Encode("path", quotaPeriodKey), 89 } 90 91 const APIVersion = "2017-03-01" 92 queryParameters := map[string]interface{}{ 93 "api-version": APIVersion, 94 } 95 96 preparer := autorest.CreatePreparer( 97 autorest.AsGet(), 98 autorest.WithCustomBaseURL("{apimBaseUrl}", urlParameters), 99 autorest.WithPathParameters("/quotas/{quotaCounterKey}/{quotaPeriodKey}", pathParameters), 100 autorest.WithQueryParameters(queryParameters)) 101 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 102} 103 104// GetSender sends the Get request. The method will close the 105// http.Response Body if it receives an error. 106func (client QuotaByPeriodKeysClient) GetSender(req *http.Request) (*http.Response, error) { 107 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 108} 109 110// GetResponder handles the response to the Get request. The method always 111// closes the http.Response Body. 112func (client QuotaByPeriodKeysClient) GetResponder(resp *http.Response) (result QuotaCounterContract, err error) { 113 err = autorest.Respond( 114 resp, 115 client.ByInspecting(), 116 azure.WithErrorUnlessStatusCode(http.StatusOK), 117 autorest.ByUnmarshallingJSON(&result), 118 autorest.ByClosing()) 119 result.Response = autorest.Response{Response: resp} 120 return 121} 122 123// Update updates an existing quota counter value in the specified service instance. 124// Parameters: 125// apimBaseURL - the management endpoint of the API Management service, for example 126// https://myapimservice.management.azure-api.net. 127// quotaCounterKey - quota counter key identifier.This is the result of expression defined in counter-key 128// attribute of the quota-by-key policy.For Example, if you specify counter-key="boo" in the policy, then it’s 129// accessible by "boo" counter key. But if it’s defined as counter-key="@("b"+"a")" then it will be accessible 130// by "ba" key 131// quotaPeriodKey - quota period key identifier. 132// parameters - the value of the Quota counter to be applied on the specified period. 133func (client QuotaByPeriodKeysClient) Update(ctx context.Context, apimBaseURL string, quotaCounterKey string, quotaPeriodKey string, parameters QuotaCounterValueContractProperties) (result autorest.Response, err error) { 134 if tracing.IsEnabled() { 135 ctx = tracing.StartSpan(ctx, fqdn+"/QuotaByPeriodKeysClient.Update") 136 defer func() { 137 sc := -1 138 if result.Response != nil { 139 sc = result.Response.StatusCode 140 } 141 tracing.EndSpan(ctx, sc, err) 142 }() 143 } 144 req, err := client.UpdatePreparer(ctx, apimBaseURL, quotaCounterKey, quotaPeriodKey, parameters) 145 if err != nil { 146 err = autorest.NewErrorWithError(err, "apimanagement.QuotaByPeriodKeysClient", "Update", nil, "Failure preparing request") 147 return 148 } 149 150 resp, err := client.UpdateSender(req) 151 if err != nil { 152 result.Response = resp 153 err = autorest.NewErrorWithError(err, "apimanagement.QuotaByPeriodKeysClient", "Update", resp, "Failure sending request") 154 return 155 } 156 157 result, err = client.UpdateResponder(resp) 158 if err != nil { 159 err = autorest.NewErrorWithError(err, "apimanagement.QuotaByPeriodKeysClient", "Update", resp, "Failure responding to request") 160 } 161 162 return 163} 164 165// UpdatePreparer prepares the Update request. 166func (client QuotaByPeriodKeysClient) UpdatePreparer(ctx context.Context, apimBaseURL string, quotaCounterKey string, quotaPeriodKey string, parameters QuotaCounterValueContractProperties) (*http.Request, error) { 167 urlParameters := map[string]interface{}{ 168 "apimBaseUrl": apimBaseURL, 169 } 170 171 pathParameters := map[string]interface{}{ 172 "quotaCounterKey": autorest.Encode("path", quotaCounterKey), 173 "quotaPeriodKey": autorest.Encode("path", quotaPeriodKey), 174 } 175 176 const APIVersion = "2017-03-01" 177 queryParameters := map[string]interface{}{ 178 "api-version": APIVersion, 179 } 180 181 preparer := autorest.CreatePreparer( 182 autorest.AsContentType("application/json; charset=utf-8"), 183 autorest.AsPatch(), 184 autorest.WithCustomBaseURL("{apimBaseUrl}", urlParameters), 185 autorest.WithPathParameters("/quotas/{quotaCounterKey}/{quotaPeriodKey}", pathParameters), 186 autorest.WithJSON(parameters), 187 autorest.WithQueryParameters(queryParameters)) 188 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 189} 190 191// UpdateSender sends the Update request. The method will close the 192// http.Response Body if it receives an error. 193func (client QuotaByPeriodKeysClient) UpdateSender(req *http.Request) (*http.Response, error) { 194 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 195} 196 197// UpdateResponder handles the response to the Update request. The method always 198// closes the http.Response Body. 199func (client QuotaByPeriodKeysClient) UpdateResponder(resp *http.Response) (result autorest.Response, err error) { 200 err = autorest.Respond( 201 resp, 202 client.ByInspecting(), 203 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 204 autorest.ByClosing()) 205 result.Response = resp 206 return 207} 208