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