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 "net/http" 26) 27 28// NotificationRecipientUserClient is the apiManagement Client 29type NotificationRecipientUserClient struct { 30 BaseClient 31} 32 33// NewNotificationRecipientUserClient creates an instance of the NotificationRecipientUserClient client. 34func NewNotificationRecipientUserClient(subscriptionID string) NotificationRecipientUserClient { 35 return NewNotificationRecipientUserClientWithBaseURI(DefaultBaseURI, subscriptionID) 36} 37 38// NewNotificationRecipientUserClientWithBaseURI creates an instance of the NotificationRecipientUserClient client. 39func NewNotificationRecipientUserClientWithBaseURI(baseURI string, subscriptionID string) NotificationRecipientUserClient { 40 return NotificationRecipientUserClient{NewWithBaseURI(baseURI, subscriptionID)} 41} 42 43// CheckEntityExists determine if the Notification Recipient User is subscribed to the notification. 44// Parameters: 45// resourceGroupName - the name of the resource group. 46// serviceName - the name of the API Management service. 47// notificationName - notification Name Identifier. 48// UID - user identifier. Must be unique in the current API Management service instance. 49func (client NotificationRecipientUserClient) CheckEntityExists(ctx context.Context, resourceGroupName string, serviceName string, notificationName NotificationName, UID string) (result autorest.Response, err error) { 50 if err := validation.Validate([]validation.Validation{ 51 {TargetValue: serviceName, 52 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 53 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 54 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 55 {TargetValue: UID, 56 Constraints: []validation.Constraint{{Target: "UID", Name: validation.MaxLength, Rule: 80, Chain: nil}, 57 {Target: "UID", Name: validation.MinLength, Rule: 1, Chain: nil}, 58 {Target: "UID", Name: validation.Pattern, Rule: `(^[\w]+$)|(^[\w][\w\-]+[\w]$)`, Chain: nil}}}}); err != nil { 59 return result, validation.NewError("apimanagement.NotificationRecipientUserClient", "CheckEntityExists", err.Error()) 60 } 61 62 req, err := client.CheckEntityExistsPreparer(ctx, resourceGroupName, serviceName, notificationName, UID) 63 if err != nil { 64 err = autorest.NewErrorWithError(err, "apimanagement.NotificationRecipientUserClient", "CheckEntityExists", nil, "Failure preparing request") 65 return 66 } 67 68 resp, err := client.CheckEntityExistsSender(req) 69 if err != nil { 70 result.Response = resp 71 err = autorest.NewErrorWithError(err, "apimanagement.NotificationRecipientUserClient", "CheckEntityExists", resp, "Failure sending request") 72 return 73 } 74 75 result, err = client.CheckEntityExistsResponder(resp) 76 if err != nil { 77 err = autorest.NewErrorWithError(err, "apimanagement.NotificationRecipientUserClient", "CheckEntityExists", resp, "Failure responding to request") 78 } 79 80 return 81} 82 83// CheckEntityExistsPreparer prepares the CheckEntityExists request. 84func (client NotificationRecipientUserClient) CheckEntityExistsPreparer(ctx context.Context, resourceGroupName string, serviceName string, notificationName NotificationName, UID string) (*http.Request, error) { 85 pathParameters := map[string]interface{}{ 86 "notificationName": autorest.Encode("path", notificationName), 87 "resourceGroupName": autorest.Encode("path", resourceGroupName), 88 "serviceName": autorest.Encode("path", serviceName), 89 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 90 "uid": autorest.Encode("path", UID), 91 } 92 93 const APIVersion = "2018-01-01" 94 queryParameters := map[string]interface{}{ 95 "api-version": APIVersion, 96 } 97 98 preparer := autorest.CreatePreparer( 99 autorest.AsHead(), 100 autorest.WithBaseURL(client.BaseURI), 101 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/notifications/{notificationName}/recipientUsers/{uid}", pathParameters), 102 autorest.WithQueryParameters(queryParameters)) 103 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 104} 105 106// CheckEntityExistsSender sends the CheckEntityExists request. The method will close the 107// http.Response Body if it receives an error. 108func (client NotificationRecipientUserClient) CheckEntityExistsSender(req *http.Request) (*http.Response, error) { 109 return autorest.SendWithSender(client, req, 110 azure.DoRetryWithRegistration(client.Client)) 111} 112 113// CheckEntityExistsResponder handles the response to the CheckEntityExists request. The method always 114// closes the http.Response Body. 115func (client NotificationRecipientUserClient) CheckEntityExistsResponder(resp *http.Response) (result autorest.Response, err error) { 116 err = autorest.Respond( 117 resp, 118 client.ByInspecting(), 119 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent, http.StatusNotFound), 120 autorest.ByClosing()) 121 result.Response = resp 122 return 123} 124 125// CreateOrUpdate adds the API Management User to the list of Recipients for the Notification. 126// Parameters: 127// resourceGroupName - the name of the resource group. 128// serviceName - the name of the API Management service. 129// notificationName - notification Name Identifier. 130// UID - user identifier. Must be unique in the current API Management service instance. 131func (client NotificationRecipientUserClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serviceName string, notificationName NotificationName, UID string) (result RecipientUserContract, err error) { 132 if err := validation.Validate([]validation.Validation{ 133 {TargetValue: serviceName, 134 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 135 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 136 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 137 {TargetValue: UID, 138 Constraints: []validation.Constraint{{Target: "UID", Name: validation.MaxLength, Rule: 80, Chain: nil}, 139 {Target: "UID", Name: validation.MinLength, Rule: 1, Chain: nil}, 140 {Target: "UID", Name: validation.Pattern, Rule: `(^[\w]+$)|(^[\w][\w\-]+[\w]$)`, Chain: nil}}}}); err != nil { 141 return result, validation.NewError("apimanagement.NotificationRecipientUserClient", "CreateOrUpdate", err.Error()) 142 } 143 144 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serviceName, notificationName, UID) 145 if err != nil { 146 err = autorest.NewErrorWithError(err, "apimanagement.NotificationRecipientUserClient", "CreateOrUpdate", nil, "Failure preparing request") 147 return 148 } 149 150 resp, err := client.CreateOrUpdateSender(req) 151 if err != nil { 152 result.Response = autorest.Response{Response: resp} 153 err = autorest.NewErrorWithError(err, "apimanagement.NotificationRecipientUserClient", "CreateOrUpdate", resp, "Failure sending request") 154 return 155 } 156 157 result, err = client.CreateOrUpdateResponder(resp) 158 if err != nil { 159 err = autorest.NewErrorWithError(err, "apimanagement.NotificationRecipientUserClient", "CreateOrUpdate", resp, "Failure responding to request") 160 } 161 162 return 163} 164 165// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 166func (client NotificationRecipientUserClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, notificationName NotificationName, UID string) (*http.Request, error) { 167 pathParameters := map[string]interface{}{ 168 "notificationName": autorest.Encode("path", notificationName), 169 "resourceGroupName": autorest.Encode("path", resourceGroupName), 170 "serviceName": autorest.Encode("path", serviceName), 171 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 172 "uid": autorest.Encode("path", UID), 173 } 174 175 const APIVersion = "2018-01-01" 176 queryParameters := map[string]interface{}{ 177 "api-version": APIVersion, 178 } 179 180 preparer := autorest.CreatePreparer( 181 autorest.AsPut(), 182 autorest.WithBaseURL(client.BaseURI), 183 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/notifications/{notificationName}/recipientUsers/{uid}", pathParameters), 184 autorest.WithQueryParameters(queryParameters)) 185 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 186} 187 188// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 189// http.Response Body if it receives an error. 190func (client NotificationRecipientUserClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { 191 return autorest.SendWithSender(client, req, 192 azure.DoRetryWithRegistration(client.Client)) 193} 194 195// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 196// closes the http.Response Body. 197func (client NotificationRecipientUserClient) CreateOrUpdateResponder(resp *http.Response) (result RecipientUserContract, err error) { 198 err = autorest.Respond( 199 resp, 200 client.ByInspecting(), 201 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 202 autorest.ByUnmarshallingJSON(&result), 203 autorest.ByClosing()) 204 result.Response = autorest.Response{Response: resp} 205 return 206} 207 208// Delete removes the API Management user from the list of Notification. 209// Parameters: 210// resourceGroupName - the name of the resource group. 211// serviceName - the name of the API Management service. 212// notificationName - notification Name Identifier. 213// UID - user identifier. Must be unique in the current API Management service instance. 214func (client NotificationRecipientUserClient) Delete(ctx context.Context, resourceGroupName string, serviceName string, notificationName NotificationName, UID string) (result autorest.Response, err error) { 215 if err := validation.Validate([]validation.Validation{ 216 {TargetValue: serviceName, 217 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 218 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 219 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 220 {TargetValue: UID, 221 Constraints: []validation.Constraint{{Target: "UID", Name: validation.MaxLength, Rule: 80, Chain: nil}, 222 {Target: "UID", Name: validation.MinLength, Rule: 1, Chain: nil}, 223 {Target: "UID", Name: validation.Pattern, Rule: `(^[\w]+$)|(^[\w][\w\-]+[\w]$)`, Chain: nil}}}}); err != nil { 224 return result, validation.NewError("apimanagement.NotificationRecipientUserClient", "Delete", err.Error()) 225 } 226 227 req, err := client.DeletePreparer(ctx, resourceGroupName, serviceName, notificationName, UID) 228 if err != nil { 229 err = autorest.NewErrorWithError(err, "apimanagement.NotificationRecipientUserClient", "Delete", nil, "Failure preparing request") 230 return 231 } 232 233 resp, err := client.DeleteSender(req) 234 if err != nil { 235 result.Response = resp 236 err = autorest.NewErrorWithError(err, "apimanagement.NotificationRecipientUserClient", "Delete", resp, "Failure sending request") 237 return 238 } 239 240 result, err = client.DeleteResponder(resp) 241 if err != nil { 242 err = autorest.NewErrorWithError(err, "apimanagement.NotificationRecipientUserClient", "Delete", resp, "Failure responding to request") 243 } 244 245 return 246} 247 248// DeletePreparer prepares the Delete request. 249func (client NotificationRecipientUserClient) DeletePreparer(ctx context.Context, resourceGroupName string, serviceName string, notificationName NotificationName, UID string) (*http.Request, error) { 250 pathParameters := map[string]interface{}{ 251 "notificationName": autorest.Encode("path", notificationName), 252 "resourceGroupName": autorest.Encode("path", resourceGroupName), 253 "serviceName": autorest.Encode("path", serviceName), 254 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 255 "uid": autorest.Encode("path", UID), 256 } 257 258 const APIVersion = "2018-01-01" 259 queryParameters := map[string]interface{}{ 260 "api-version": APIVersion, 261 } 262 263 preparer := autorest.CreatePreparer( 264 autorest.AsDelete(), 265 autorest.WithBaseURL(client.BaseURI), 266 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/notifications/{notificationName}/recipientUsers/{uid}", pathParameters), 267 autorest.WithQueryParameters(queryParameters)) 268 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 269} 270 271// DeleteSender sends the Delete request. The method will close the 272// http.Response Body if it receives an error. 273func (client NotificationRecipientUserClient) DeleteSender(req *http.Request) (*http.Response, error) { 274 return autorest.SendWithSender(client, req, 275 azure.DoRetryWithRegistration(client.Client)) 276} 277 278// DeleteResponder handles the response to the Delete request. The method always 279// closes the http.Response Body. 280func (client NotificationRecipientUserClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 281 err = autorest.Respond( 282 resp, 283 client.ByInspecting(), 284 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 285 autorest.ByClosing()) 286 result.Response = resp 287 return 288} 289 290// ListByNotification gets the list of the Notification Recipient User subscribed to the notification. 291// Parameters: 292// resourceGroupName - the name of the resource group. 293// serviceName - the name of the API Management service. 294// notificationName - notification Name Identifier. 295func (client NotificationRecipientUserClient) ListByNotification(ctx context.Context, resourceGroupName string, serviceName string, notificationName NotificationName) (result RecipientUserCollection, err error) { 296 if err := validation.Validate([]validation.Validation{ 297 {TargetValue: serviceName, 298 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 299 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 300 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}}); err != nil { 301 return result, validation.NewError("apimanagement.NotificationRecipientUserClient", "ListByNotification", err.Error()) 302 } 303 304 req, err := client.ListByNotificationPreparer(ctx, resourceGroupName, serviceName, notificationName) 305 if err != nil { 306 err = autorest.NewErrorWithError(err, "apimanagement.NotificationRecipientUserClient", "ListByNotification", nil, "Failure preparing request") 307 return 308 } 309 310 resp, err := client.ListByNotificationSender(req) 311 if err != nil { 312 result.Response = autorest.Response{Response: resp} 313 err = autorest.NewErrorWithError(err, "apimanagement.NotificationRecipientUserClient", "ListByNotification", resp, "Failure sending request") 314 return 315 } 316 317 result, err = client.ListByNotificationResponder(resp) 318 if err != nil { 319 err = autorest.NewErrorWithError(err, "apimanagement.NotificationRecipientUserClient", "ListByNotification", resp, "Failure responding to request") 320 } 321 322 return 323} 324 325// ListByNotificationPreparer prepares the ListByNotification request. 326func (client NotificationRecipientUserClient) ListByNotificationPreparer(ctx context.Context, resourceGroupName string, serviceName string, notificationName NotificationName) (*http.Request, error) { 327 pathParameters := map[string]interface{}{ 328 "notificationName": autorest.Encode("path", notificationName), 329 "resourceGroupName": autorest.Encode("path", resourceGroupName), 330 "serviceName": autorest.Encode("path", serviceName), 331 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 332 } 333 334 const APIVersion = "2018-01-01" 335 queryParameters := map[string]interface{}{ 336 "api-version": APIVersion, 337 } 338 339 preparer := autorest.CreatePreparer( 340 autorest.AsGet(), 341 autorest.WithBaseURL(client.BaseURI), 342 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/notifications/{notificationName}/recipientUsers", pathParameters), 343 autorest.WithQueryParameters(queryParameters)) 344 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 345} 346 347// ListByNotificationSender sends the ListByNotification request. The method will close the 348// http.Response Body if it receives an error. 349func (client NotificationRecipientUserClient) ListByNotificationSender(req *http.Request) (*http.Response, error) { 350 return autorest.SendWithSender(client, req, 351 azure.DoRetryWithRegistration(client.Client)) 352} 353 354// ListByNotificationResponder handles the response to the ListByNotification request. The method always 355// closes the http.Response Body. 356func (client NotificationRecipientUserClient) ListByNotificationResponder(resp *http.Response) (result RecipientUserCollection, err error) { 357 err = autorest.Respond( 358 resp, 359 client.ByInspecting(), 360 azure.WithErrorUnlessStatusCode(http.StatusOK), 361 autorest.ByUnmarshallingJSON(&result), 362 autorest.ByClosing()) 363 result.Response = autorest.Response{Response: resp} 364 return 365} 366