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/autorest/validation" 25 "github.com/Azure/go-autorest/tracing" 26 "net/http" 27) 28 29// NotificationClient is the apiManagement Client 30type NotificationClient struct { 31 BaseClient 32} 33 34// NewNotificationClient creates an instance of the NotificationClient client. 35func NewNotificationClient(subscriptionID string) NotificationClient { 36 return NewNotificationClientWithBaseURI(DefaultBaseURI, subscriptionID) 37} 38 39// NewNotificationClientWithBaseURI creates an instance of the NotificationClient client using a custom endpoint. Use 40// this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 41func NewNotificationClientWithBaseURI(baseURI string, subscriptionID string) NotificationClient { 42 return NotificationClient{NewWithBaseURI(baseURI, subscriptionID)} 43} 44 45// CreateOrUpdate create or Update API Management publisher notification. 46// Parameters: 47// resourceGroupName - the name of the resource group. 48// serviceName - the name of the API Management service. 49// notificationName - notification Name Identifier. 50// ifMatch - eTag of the Entity. Not required when creating an entity, but required when updating an entity. 51func (client NotificationClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serviceName string, notificationName NotificationName, ifMatch string) (result NotificationContract, err error) { 52 if tracing.IsEnabled() { 53 ctx = tracing.StartSpan(ctx, fqdn+"/NotificationClient.CreateOrUpdate") 54 defer func() { 55 sc := -1 56 if result.Response.Response != nil { 57 sc = result.Response.Response.StatusCode 58 } 59 tracing.EndSpan(ctx, sc, err) 60 }() 61 } 62 if err := validation.Validate([]validation.Validation{ 63 {TargetValue: serviceName, 64 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 65 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 66 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}}); err != nil { 67 return result, validation.NewError("apimanagement.NotificationClient", "CreateOrUpdate", err.Error()) 68 } 69 70 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serviceName, notificationName, ifMatch) 71 if err != nil { 72 err = autorest.NewErrorWithError(err, "apimanagement.NotificationClient", "CreateOrUpdate", nil, "Failure preparing request") 73 return 74 } 75 76 resp, err := client.CreateOrUpdateSender(req) 77 if err != nil { 78 result.Response = autorest.Response{Response: resp} 79 err = autorest.NewErrorWithError(err, "apimanagement.NotificationClient", "CreateOrUpdate", resp, "Failure sending request") 80 return 81 } 82 83 result, err = client.CreateOrUpdateResponder(resp) 84 if err != nil { 85 err = autorest.NewErrorWithError(err, "apimanagement.NotificationClient", "CreateOrUpdate", resp, "Failure responding to request") 86 return 87 } 88 89 return 90} 91 92// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 93func (client NotificationClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, notificationName NotificationName, ifMatch string) (*http.Request, error) { 94 pathParameters := map[string]interface{}{ 95 "notificationName": autorest.Encode("path", notificationName), 96 "resourceGroupName": autorest.Encode("path", resourceGroupName), 97 "serviceName": autorest.Encode("path", serviceName), 98 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 99 } 100 101 const APIVersion = "2020-12-01" 102 queryParameters := map[string]interface{}{ 103 "api-version": APIVersion, 104 } 105 106 preparer := autorest.CreatePreparer( 107 autorest.AsPut(), 108 autorest.WithBaseURL(client.BaseURI), 109 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/notifications/{notificationName}", pathParameters), 110 autorest.WithQueryParameters(queryParameters)) 111 if len(ifMatch) > 0 { 112 preparer = autorest.DecoratePreparer(preparer, 113 autorest.WithHeader("If-Match", autorest.String(ifMatch))) 114 } 115 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 116} 117 118// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 119// http.Response Body if it receives an error. 120func (client NotificationClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { 121 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 122} 123 124// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 125// closes the http.Response Body. 126func (client NotificationClient) CreateOrUpdateResponder(resp *http.Response) (result NotificationContract, err error) { 127 err = autorest.Respond( 128 resp, 129 azure.WithErrorUnlessStatusCode(http.StatusOK), 130 autorest.ByUnmarshallingJSON(&result), 131 autorest.ByClosing()) 132 result.Response = autorest.Response{Response: resp} 133 return 134} 135 136// Get gets the details of the Notification specified by its identifier. 137// Parameters: 138// resourceGroupName - the name of the resource group. 139// serviceName - the name of the API Management service. 140// notificationName - notification Name Identifier. 141func (client NotificationClient) Get(ctx context.Context, resourceGroupName string, serviceName string, notificationName NotificationName) (result NotificationContract, err error) { 142 if tracing.IsEnabled() { 143 ctx = tracing.StartSpan(ctx, fqdn+"/NotificationClient.Get") 144 defer func() { 145 sc := -1 146 if result.Response.Response != nil { 147 sc = result.Response.Response.StatusCode 148 } 149 tracing.EndSpan(ctx, sc, err) 150 }() 151 } 152 if err := validation.Validate([]validation.Validation{ 153 {TargetValue: serviceName, 154 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 155 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 156 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}}); err != nil { 157 return result, validation.NewError("apimanagement.NotificationClient", "Get", err.Error()) 158 } 159 160 req, err := client.GetPreparer(ctx, resourceGroupName, serviceName, notificationName) 161 if err != nil { 162 err = autorest.NewErrorWithError(err, "apimanagement.NotificationClient", "Get", nil, "Failure preparing request") 163 return 164 } 165 166 resp, err := client.GetSender(req) 167 if err != nil { 168 result.Response = autorest.Response{Response: resp} 169 err = autorest.NewErrorWithError(err, "apimanagement.NotificationClient", "Get", resp, "Failure sending request") 170 return 171 } 172 173 result, err = client.GetResponder(resp) 174 if err != nil { 175 err = autorest.NewErrorWithError(err, "apimanagement.NotificationClient", "Get", resp, "Failure responding to request") 176 return 177 } 178 179 return 180} 181 182// GetPreparer prepares the Get request. 183func (client NotificationClient) GetPreparer(ctx context.Context, resourceGroupName string, serviceName string, notificationName NotificationName) (*http.Request, error) { 184 pathParameters := map[string]interface{}{ 185 "notificationName": autorest.Encode("path", notificationName), 186 "resourceGroupName": autorest.Encode("path", resourceGroupName), 187 "serviceName": autorest.Encode("path", serviceName), 188 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 189 } 190 191 const APIVersion = "2020-12-01" 192 queryParameters := map[string]interface{}{ 193 "api-version": APIVersion, 194 } 195 196 preparer := autorest.CreatePreparer( 197 autorest.AsGet(), 198 autorest.WithBaseURL(client.BaseURI), 199 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/notifications/{notificationName}", pathParameters), 200 autorest.WithQueryParameters(queryParameters)) 201 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 202} 203 204// GetSender sends the Get request. The method will close the 205// http.Response Body if it receives an error. 206func (client NotificationClient) GetSender(req *http.Request) (*http.Response, error) { 207 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 208} 209 210// GetResponder handles the response to the Get request. The method always 211// closes the http.Response Body. 212func (client NotificationClient) GetResponder(resp *http.Response) (result NotificationContract, err error) { 213 err = autorest.Respond( 214 resp, 215 azure.WithErrorUnlessStatusCode(http.StatusOK), 216 autorest.ByUnmarshallingJSON(&result), 217 autorest.ByClosing()) 218 result.Response = autorest.Response{Response: resp} 219 return 220} 221 222// ListByService lists a collection of properties defined within a service instance. 223// Parameters: 224// resourceGroupName - the name of the resource group. 225// serviceName - the name of the API Management service. 226// top - number of records to return. 227// skip - number of records to skip. 228func (client NotificationClient) ListByService(ctx context.Context, resourceGroupName string, serviceName string, top *int32, skip *int32) (result NotificationCollectionPage, err error) { 229 if tracing.IsEnabled() { 230 ctx = tracing.StartSpan(ctx, fqdn+"/NotificationClient.ListByService") 231 defer func() { 232 sc := -1 233 if result.nc.Response.Response != nil { 234 sc = result.nc.Response.Response.StatusCode 235 } 236 tracing.EndSpan(ctx, sc, err) 237 }() 238 } 239 if err := validation.Validate([]validation.Validation{ 240 {TargetValue: serviceName, 241 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 242 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 243 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 244 {TargetValue: top, 245 Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, 246 Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil}}}}}, 247 {TargetValue: skip, 248 Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false, 249 Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil { 250 return result, validation.NewError("apimanagement.NotificationClient", "ListByService", err.Error()) 251 } 252 253 result.fn = client.listByServiceNextResults 254 req, err := client.ListByServicePreparer(ctx, resourceGroupName, serviceName, top, skip) 255 if err != nil { 256 err = autorest.NewErrorWithError(err, "apimanagement.NotificationClient", "ListByService", nil, "Failure preparing request") 257 return 258 } 259 260 resp, err := client.ListByServiceSender(req) 261 if err != nil { 262 result.nc.Response = autorest.Response{Response: resp} 263 err = autorest.NewErrorWithError(err, "apimanagement.NotificationClient", "ListByService", resp, "Failure sending request") 264 return 265 } 266 267 result.nc, err = client.ListByServiceResponder(resp) 268 if err != nil { 269 err = autorest.NewErrorWithError(err, "apimanagement.NotificationClient", "ListByService", resp, "Failure responding to request") 270 return 271 } 272 if result.nc.hasNextLink() && result.nc.IsEmpty() { 273 err = result.NextWithContext(ctx) 274 return 275 } 276 277 return 278} 279 280// ListByServicePreparer prepares the ListByService request. 281func (client NotificationClient) ListByServicePreparer(ctx context.Context, resourceGroupName string, serviceName string, top *int32, skip *int32) (*http.Request, error) { 282 pathParameters := map[string]interface{}{ 283 "resourceGroupName": autorest.Encode("path", resourceGroupName), 284 "serviceName": autorest.Encode("path", serviceName), 285 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 286 } 287 288 const APIVersion = "2020-12-01" 289 queryParameters := map[string]interface{}{ 290 "api-version": APIVersion, 291 } 292 if top != nil { 293 queryParameters["$top"] = autorest.Encode("query", *top) 294 } 295 if skip != nil { 296 queryParameters["$skip"] = autorest.Encode("query", *skip) 297 } 298 299 preparer := autorest.CreatePreparer( 300 autorest.AsGet(), 301 autorest.WithBaseURL(client.BaseURI), 302 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/notifications", pathParameters), 303 autorest.WithQueryParameters(queryParameters)) 304 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 305} 306 307// ListByServiceSender sends the ListByService request. The method will close the 308// http.Response Body if it receives an error. 309func (client NotificationClient) ListByServiceSender(req *http.Request) (*http.Response, error) { 310 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 311} 312 313// ListByServiceResponder handles the response to the ListByService request. The method always 314// closes the http.Response Body. 315func (client NotificationClient) ListByServiceResponder(resp *http.Response) (result NotificationCollection, err error) { 316 err = autorest.Respond( 317 resp, 318 azure.WithErrorUnlessStatusCode(http.StatusOK), 319 autorest.ByUnmarshallingJSON(&result), 320 autorest.ByClosing()) 321 result.Response = autorest.Response{Response: resp} 322 return 323} 324 325// listByServiceNextResults retrieves the next set of results, if any. 326func (client NotificationClient) listByServiceNextResults(ctx context.Context, lastResults NotificationCollection) (result NotificationCollection, err error) { 327 req, err := lastResults.notificationCollectionPreparer(ctx) 328 if err != nil { 329 return result, autorest.NewErrorWithError(err, "apimanagement.NotificationClient", "listByServiceNextResults", nil, "Failure preparing next results request") 330 } 331 if req == nil { 332 return 333 } 334 resp, err := client.ListByServiceSender(req) 335 if err != nil { 336 result.Response = autorest.Response{Response: resp} 337 return result, autorest.NewErrorWithError(err, "apimanagement.NotificationClient", "listByServiceNextResults", resp, "Failure sending next results request") 338 } 339 result, err = client.ListByServiceResponder(resp) 340 if err != nil { 341 err = autorest.NewErrorWithError(err, "apimanagement.NotificationClient", "listByServiceNextResults", resp, "Failure responding to next results request") 342 } 343 return 344} 345 346// ListByServiceComplete enumerates all values, automatically crossing page boundaries as required. 347func (client NotificationClient) ListByServiceComplete(ctx context.Context, resourceGroupName string, serviceName string, top *int32, skip *int32) (result NotificationCollectionIterator, err error) { 348 if tracing.IsEnabled() { 349 ctx = tracing.StartSpan(ctx, fqdn+"/NotificationClient.ListByService") 350 defer func() { 351 sc := -1 352 if result.Response().Response.Response != nil { 353 sc = result.page.Response().Response.Response.StatusCode 354 } 355 tracing.EndSpan(ctx, sc, err) 356 }() 357 } 358 result.page, err = client.ListByService(ctx, resourceGroupName, serviceName, top, skip) 359 return 360} 361