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