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// CreateOrUpdate adds the API Management User to the list of Recipients for 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) CreateOrUpdate(ctx context.Context, resourceGroupName string, serviceName string, notificationName NotificationName, UID string) (result RecipientUserContract, 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: 256, Chain: nil},
57				{Target: "UID", Name: validation.MinLength, Rule: 1, Chain: nil},
58				{Target: "UID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
59		return result, validation.NewError("apimanagement.NotificationRecipientUserClient", "CreateOrUpdate", err.Error())
60	}
61
62	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serviceName, notificationName, UID)
63	if err != nil {
64		err = autorest.NewErrorWithError(err, "apimanagement.NotificationRecipientUserClient", "CreateOrUpdate", nil, "Failure preparing request")
65		return
66	}
67
68	resp, err := client.CreateOrUpdateSender(req)
69	if err != nil {
70		result.Response = autorest.Response{Response: resp}
71		err = autorest.NewErrorWithError(err, "apimanagement.NotificationRecipientUserClient", "CreateOrUpdate", resp, "Failure sending request")
72		return
73	}
74
75	result, err = client.CreateOrUpdateResponder(resp)
76	if err != nil {
77		err = autorest.NewErrorWithError(err, "apimanagement.NotificationRecipientUserClient", "CreateOrUpdate", resp, "Failure responding to request")
78	}
79
80	return
81}
82
83// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
84func (client NotificationRecipientUserClient) CreateOrUpdatePreparer(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 = "2017-03-01"
94	queryParameters := map[string]interface{}{
95		"api-version": APIVersion,
96	}
97
98	preparer := autorest.CreatePreparer(
99		autorest.AsPut(),
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// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
107// http.Response Body if it receives an error.
108func (client NotificationRecipientUserClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
109	return autorest.SendWithSender(client, req,
110		azure.DoRetryWithRegistration(client.Client))
111}
112
113// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
114// closes the http.Response Body.
115func (client NotificationRecipientUserClient) CreateOrUpdateResponder(resp *http.Response) (result RecipientUserContract, err error) {
116	err = autorest.Respond(
117		resp,
118		client.ByInspecting(),
119		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
120		autorest.ByUnmarshallingJSON(&result),
121		autorest.ByClosing())
122	result.Response = autorest.Response{Response: resp}
123	return
124}
125
126// Delete removes the API Management user from the list of 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// UID - user identifier. Must be unique in the current API Management service instance.
132func (client NotificationRecipientUserClient) Delete(ctx context.Context, resourceGroupName string, serviceName string, notificationName NotificationName, UID string) (result autorest.Response, err error) {
133	if err := validation.Validate([]validation.Validation{
134		{TargetValue: serviceName,
135			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
136				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
137				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
138		{TargetValue: UID,
139			Constraints: []validation.Constraint{{Target: "UID", Name: validation.MaxLength, Rule: 256, Chain: nil},
140				{Target: "UID", Name: validation.MinLength, Rule: 1, Chain: nil},
141				{Target: "UID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
142		return result, validation.NewError("apimanagement.NotificationRecipientUserClient", "Delete", err.Error())
143	}
144
145	req, err := client.DeletePreparer(ctx, resourceGroupName, serviceName, notificationName, UID)
146	if err != nil {
147		err = autorest.NewErrorWithError(err, "apimanagement.NotificationRecipientUserClient", "Delete", nil, "Failure preparing request")
148		return
149	}
150
151	resp, err := client.DeleteSender(req)
152	if err != nil {
153		result.Response = resp
154		err = autorest.NewErrorWithError(err, "apimanagement.NotificationRecipientUserClient", "Delete", resp, "Failure sending request")
155		return
156	}
157
158	result, err = client.DeleteResponder(resp)
159	if err != nil {
160		err = autorest.NewErrorWithError(err, "apimanagement.NotificationRecipientUserClient", "Delete", resp, "Failure responding to request")
161	}
162
163	return
164}
165
166// DeletePreparer prepares the Delete request.
167func (client NotificationRecipientUserClient) DeletePreparer(ctx context.Context, resourceGroupName string, serviceName string, notificationName NotificationName, UID string) (*http.Request, error) {
168	pathParameters := map[string]interface{}{
169		"notificationName":  autorest.Encode("path", notificationName),
170		"resourceGroupName": autorest.Encode("path", resourceGroupName),
171		"serviceName":       autorest.Encode("path", serviceName),
172		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
173		"uid":               autorest.Encode("path", UID),
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.AsDelete(),
183		autorest.WithBaseURL(client.BaseURI),
184		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/notifications/{notificationName}/recipientUsers/{uid}", pathParameters),
185		autorest.WithQueryParameters(queryParameters))
186	return preparer.Prepare((&http.Request{}).WithContext(ctx))
187}
188
189// DeleteSender sends the Delete request. The method will close the
190// http.Response Body if it receives an error.
191func (client NotificationRecipientUserClient) DeleteSender(req *http.Request) (*http.Response, error) {
192	return autorest.SendWithSender(client, req,
193		azure.DoRetryWithRegistration(client.Client))
194}
195
196// DeleteResponder handles the response to the Delete request. The method always
197// closes the http.Response Body.
198func (client NotificationRecipientUserClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
199	err = autorest.Respond(
200		resp,
201		client.ByInspecting(),
202		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
203		autorest.ByClosing())
204	result.Response = resp
205	return
206}
207
208// Get determine if the Notification Recipient User is subscribed to the 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) Get(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: 256, Chain: nil},
222				{Target: "UID", Name: validation.MinLength, Rule: 1, Chain: nil},
223				{Target: "UID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
224		return result, validation.NewError("apimanagement.NotificationRecipientUserClient", "Get", err.Error())
225	}
226
227	req, err := client.GetPreparer(ctx, resourceGroupName, serviceName, notificationName, UID)
228	if err != nil {
229		err = autorest.NewErrorWithError(err, "apimanagement.NotificationRecipientUserClient", "Get", nil, "Failure preparing request")
230		return
231	}
232
233	resp, err := client.GetSender(req)
234	if err != nil {
235		result.Response = resp
236		err = autorest.NewErrorWithError(err, "apimanagement.NotificationRecipientUserClient", "Get", resp, "Failure sending request")
237		return
238	}
239
240	result, err = client.GetResponder(resp)
241	if err != nil {
242		err = autorest.NewErrorWithError(err, "apimanagement.NotificationRecipientUserClient", "Get", resp, "Failure responding to request")
243	}
244
245	return
246}
247
248// GetPreparer prepares the Get request.
249func (client NotificationRecipientUserClient) GetPreparer(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 = "2017-03-01"
259	queryParameters := map[string]interface{}{
260		"api-version": APIVersion,
261	}
262
263	preparer := autorest.CreatePreparer(
264		autorest.AsHead(),
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// GetSender sends the Get request. The method will close the
272// http.Response Body if it receives an error.
273func (client NotificationRecipientUserClient) GetSender(req *http.Request) (*http.Response, error) {
274	return autorest.SendWithSender(client, req,
275		azure.DoRetryWithRegistration(client.Client))
276}
277
278// GetResponder handles the response to the Get request. The method always
279// closes the http.Response Body.
280func (client NotificationRecipientUserClient) GetResponder(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 = "2017-03-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