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