1package notificationhubs
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// Client is the azure NotificationHub client
19type Client struct {
20	BaseClient
21}
22
23// NewClient creates an instance of the Client client.
24func NewClient(subscriptionID string) Client {
25	return NewClientWithBaseURI(DefaultBaseURI, subscriptionID)
26}
27
28// NewClientWithBaseURI creates an instance of the Client client using a custom endpoint.  Use this when interacting
29// with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
30func NewClientWithBaseURI(baseURI string, subscriptionID string) Client {
31	return Client{NewWithBaseURI(baseURI, subscriptionID)}
32}
33
34// CheckAvailability checks the availability of the given notificationHub in a namespace.
35// Parameters:
36// resourceGroupName - the name of the resource group.
37// namespaceName - the namespace name.
38// parameters - the notificationHub name.
39func (client Client) CheckAvailability(ctx context.Context, resourceGroupName string, namespaceName string, parameters CheckAvailabilityParameters) (result CheckAvailabilityResource, err error) {
40	if tracing.IsEnabled() {
41		ctx = tracing.StartSpan(ctx, fqdn+"/Client.CheckAvailability")
42		defer func() {
43			sc := -1
44			if result.Response.Response != nil {
45				sc = result.Response.Response.StatusCode
46			}
47			tracing.EndSpan(ctx, sc, err)
48		}()
49	}
50	if err := validation.Validate([]validation.Validation{
51		{TargetValue: parameters,
52			Constraints: []validation.Constraint{{Target: "parameters.Name", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
53		return result, validation.NewError("notificationhubs.Client", "CheckAvailability", err.Error())
54	}
55
56	req, err := client.CheckAvailabilityPreparer(ctx, resourceGroupName, namespaceName, parameters)
57	if err != nil {
58		err = autorest.NewErrorWithError(err, "notificationhubs.Client", "CheckAvailability", nil, "Failure preparing request")
59		return
60	}
61
62	resp, err := client.CheckAvailabilitySender(req)
63	if err != nil {
64		result.Response = autorest.Response{Response: resp}
65		err = autorest.NewErrorWithError(err, "notificationhubs.Client", "CheckAvailability", resp, "Failure sending request")
66		return
67	}
68
69	result, err = client.CheckAvailabilityResponder(resp)
70	if err != nil {
71		err = autorest.NewErrorWithError(err, "notificationhubs.Client", "CheckAvailability", resp, "Failure responding to request")
72		return
73	}
74
75	return
76}
77
78// CheckAvailabilityPreparer prepares the CheckAvailability request.
79func (client Client) CheckAvailabilityPreparer(ctx context.Context, resourceGroupName string, namespaceName string, parameters CheckAvailabilityParameters) (*http.Request, error) {
80	pathParameters := map[string]interface{}{
81		"namespaceName":     autorest.Encode("path", namespaceName),
82		"resourceGroupName": autorest.Encode("path", resourceGroupName),
83		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
84	}
85
86	const APIVersion = "2014-09-01"
87	queryParameters := map[string]interface{}{
88		"api-version": APIVersion,
89	}
90
91	preparer := autorest.CreatePreparer(
92		autorest.AsContentType("application/json; charset=utf-8"),
93		autorest.AsPost(),
94		autorest.WithBaseURL(client.BaseURI),
95		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NotificationHubs/namespaces/{namespaceName}/checkNotificationHubAvailability", pathParameters),
96		autorest.WithJSON(parameters),
97		autorest.WithQueryParameters(queryParameters))
98	return preparer.Prepare((&http.Request{}).WithContext(ctx))
99}
100
101// CheckAvailabilitySender sends the CheckAvailability request. The method will close the
102// http.Response Body if it receives an error.
103func (client Client) CheckAvailabilitySender(req *http.Request) (*http.Response, error) {
104	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
105}
106
107// CheckAvailabilityResponder handles the response to the CheckAvailability request. The method always
108// closes the http.Response Body.
109func (client Client) CheckAvailabilityResponder(resp *http.Response) (result CheckAvailabilityResource, err error) {
110	err = autorest.Respond(
111		resp,
112		azure.WithErrorUnlessStatusCode(http.StatusOK),
113		autorest.ByUnmarshallingJSON(&result),
114		autorest.ByClosing())
115	result.Response = autorest.Response{Response: resp}
116	return
117}
118
119// CreateOrUpdate creates/Update a NotificationHub in a namespace.
120// Parameters:
121// resourceGroupName - the name of the resource group.
122// namespaceName - the namespace name.
123// notificationHubName - the notification hub name.
124// parameters - parameters supplied to the create/update a NotificationHub Resource.
125func (client Client) CreateOrUpdate(ctx context.Context, resourceGroupName string, namespaceName string, notificationHubName string, parameters CreateOrUpdateParameters) (result ResourceType, err error) {
126	if tracing.IsEnabled() {
127		ctx = tracing.StartSpan(ctx, fqdn+"/Client.CreateOrUpdate")
128		defer func() {
129			sc := -1
130			if result.Response.Response != nil {
131				sc = result.Response.Response.StatusCode
132			}
133			tracing.EndSpan(ctx, sc, err)
134		}()
135	}
136	if err := validation.Validate([]validation.Validation{
137		{TargetValue: parameters,
138			Constraints: []validation.Constraint{{Target: "parameters.Location", Name: validation.Null, Rule: true, Chain: nil},
139				{Target: "parameters.Properties", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
140		return result, validation.NewError("notificationhubs.Client", "CreateOrUpdate", err.Error())
141	}
142
143	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, namespaceName, notificationHubName, parameters)
144	if err != nil {
145		err = autorest.NewErrorWithError(err, "notificationhubs.Client", "CreateOrUpdate", nil, "Failure preparing request")
146		return
147	}
148
149	resp, err := client.CreateOrUpdateSender(req)
150	if err != nil {
151		result.Response = autorest.Response{Response: resp}
152		err = autorest.NewErrorWithError(err, "notificationhubs.Client", "CreateOrUpdate", resp, "Failure sending request")
153		return
154	}
155
156	result, err = client.CreateOrUpdateResponder(resp)
157	if err != nil {
158		err = autorest.NewErrorWithError(err, "notificationhubs.Client", "CreateOrUpdate", resp, "Failure responding to request")
159		return
160	}
161
162	return
163}
164
165// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
166func (client Client) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, namespaceName string, notificationHubName string, parameters CreateOrUpdateParameters) (*http.Request, error) {
167	pathParameters := map[string]interface{}{
168		"namespaceName":       autorest.Encode("path", namespaceName),
169		"notificationHubName": autorest.Encode("path", notificationHubName),
170		"resourceGroupName":   autorest.Encode("path", resourceGroupName),
171		"subscriptionId":      autorest.Encode("path", client.SubscriptionID),
172	}
173
174	const APIVersion = "2014-09-01"
175	queryParameters := map[string]interface{}{
176		"api-version": APIVersion,
177	}
178
179	preparer := autorest.CreatePreparer(
180		autorest.AsContentType("application/json; charset=utf-8"),
181		autorest.AsPut(),
182		autorest.WithBaseURL(client.BaseURI),
183		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NotificationHubs/namespaces/{namespaceName}/notificationHubs/{notificationHubName}", pathParameters),
184		autorest.WithJSON(parameters),
185		autorest.WithQueryParameters(queryParameters))
186	return preparer.Prepare((&http.Request{}).WithContext(ctx))
187}
188
189// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
190// http.Response Body if it receives an error.
191func (client Client) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
192	return client.Send(req, 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 Client) CreateOrUpdateResponder(resp *http.Response) (result ResourceType, err error) {
198	err = autorest.Respond(
199		resp,
200		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
201		autorest.ByUnmarshallingJSON(&result),
202		autorest.ByClosing())
203	result.Response = autorest.Response{Response: resp}
204	return
205}
206
207// CreateOrUpdateAuthorizationRule creates/Updates an authorization rule for a NotificationHub
208// Parameters:
209// resourceGroupName - the name of the resource group.
210// namespaceName - the namespace name.
211// notificationHubName - the notification hub name.
212// authorizationRuleName - authorization Rule Name.
213// parameters - the shared access authorization rule.
214func (client Client) CreateOrUpdateAuthorizationRule(ctx context.Context, resourceGroupName string, namespaceName string, notificationHubName string, authorizationRuleName string, parameters SharedAccessAuthorizationRuleCreateOrUpdateParameters) (result SharedAccessAuthorizationRuleResource, err error) {
215	if tracing.IsEnabled() {
216		ctx = tracing.StartSpan(ctx, fqdn+"/Client.CreateOrUpdateAuthorizationRule")
217		defer func() {
218			sc := -1
219			if result.Response.Response != nil {
220				sc = result.Response.Response.StatusCode
221			}
222			tracing.EndSpan(ctx, sc, err)
223		}()
224	}
225	if err := validation.Validate([]validation.Validation{
226		{TargetValue: parameters,
227			Constraints: []validation.Constraint{{Target: "parameters.Properties", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
228		return result, validation.NewError("notificationhubs.Client", "CreateOrUpdateAuthorizationRule", err.Error())
229	}
230
231	req, err := client.CreateOrUpdateAuthorizationRulePreparer(ctx, resourceGroupName, namespaceName, notificationHubName, authorizationRuleName, parameters)
232	if err != nil {
233		err = autorest.NewErrorWithError(err, "notificationhubs.Client", "CreateOrUpdateAuthorizationRule", nil, "Failure preparing request")
234		return
235	}
236
237	resp, err := client.CreateOrUpdateAuthorizationRuleSender(req)
238	if err != nil {
239		result.Response = autorest.Response{Response: resp}
240		err = autorest.NewErrorWithError(err, "notificationhubs.Client", "CreateOrUpdateAuthorizationRule", resp, "Failure sending request")
241		return
242	}
243
244	result, err = client.CreateOrUpdateAuthorizationRuleResponder(resp)
245	if err != nil {
246		err = autorest.NewErrorWithError(err, "notificationhubs.Client", "CreateOrUpdateAuthorizationRule", resp, "Failure responding to request")
247		return
248	}
249
250	return
251}
252
253// CreateOrUpdateAuthorizationRulePreparer prepares the CreateOrUpdateAuthorizationRule request.
254func (client Client) CreateOrUpdateAuthorizationRulePreparer(ctx context.Context, resourceGroupName string, namespaceName string, notificationHubName string, authorizationRuleName string, parameters SharedAccessAuthorizationRuleCreateOrUpdateParameters) (*http.Request, error) {
255	pathParameters := map[string]interface{}{
256		"authorizationRuleName": autorest.Encode("path", authorizationRuleName),
257		"namespaceName":         autorest.Encode("path", namespaceName),
258		"notificationHubName":   autorest.Encode("path", notificationHubName),
259		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
260		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
261	}
262
263	const APIVersion = "2014-09-01"
264	queryParameters := map[string]interface{}{
265		"api-version": APIVersion,
266	}
267
268	preparer := autorest.CreatePreparer(
269		autorest.AsContentType("application/json; charset=utf-8"),
270		autorest.AsPut(),
271		autorest.WithBaseURL(client.BaseURI),
272		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NotificationHubs/namespaces/{namespaceName}/notificationHubs/{notificationHubName}/AuthorizationRules/{authorizationRuleName}", pathParameters),
273		autorest.WithJSON(parameters),
274		autorest.WithQueryParameters(queryParameters))
275	return preparer.Prepare((&http.Request{}).WithContext(ctx))
276}
277
278// CreateOrUpdateAuthorizationRuleSender sends the CreateOrUpdateAuthorizationRule request. The method will close the
279// http.Response Body if it receives an error.
280func (client Client) CreateOrUpdateAuthorizationRuleSender(req *http.Request) (*http.Response, error) {
281	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
282}
283
284// CreateOrUpdateAuthorizationRuleResponder handles the response to the CreateOrUpdateAuthorizationRule request. The method always
285// closes the http.Response Body.
286func (client Client) CreateOrUpdateAuthorizationRuleResponder(resp *http.Response) (result SharedAccessAuthorizationRuleResource, err error) {
287	err = autorest.Respond(
288		resp,
289		azure.WithErrorUnlessStatusCode(http.StatusOK),
290		autorest.ByUnmarshallingJSON(&result),
291		autorest.ByClosing())
292	result.Response = autorest.Response{Response: resp}
293	return
294}
295
296// Delete deletes a notification hub associated with a namespace.
297// Parameters:
298// resourceGroupName - the name of the resource group.
299// namespaceName - the namespace name.
300// notificationHubName - the notification hub name.
301func (client Client) Delete(ctx context.Context, resourceGroupName string, namespaceName string, notificationHubName string) (result autorest.Response, err error) {
302	if tracing.IsEnabled() {
303		ctx = tracing.StartSpan(ctx, fqdn+"/Client.Delete")
304		defer func() {
305			sc := -1
306			if result.Response != nil {
307				sc = result.Response.StatusCode
308			}
309			tracing.EndSpan(ctx, sc, err)
310		}()
311	}
312	req, err := client.DeletePreparer(ctx, resourceGroupName, namespaceName, notificationHubName)
313	if err != nil {
314		err = autorest.NewErrorWithError(err, "notificationhubs.Client", "Delete", nil, "Failure preparing request")
315		return
316	}
317
318	resp, err := client.DeleteSender(req)
319	if err != nil {
320		result.Response = resp
321		err = autorest.NewErrorWithError(err, "notificationhubs.Client", "Delete", resp, "Failure sending request")
322		return
323	}
324
325	result, err = client.DeleteResponder(resp)
326	if err != nil {
327		err = autorest.NewErrorWithError(err, "notificationhubs.Client", "Delete", resp, "Failure responding to request")
328		return
329	}
330
331	return
332}
333
334// DeletePreparer prepares the Delete request.
335func (client Client) DeletePreparer(ctx context.Context, resourceGroupName string, namespaceName string, notificationHubName string) (*http.Request, error) {
336	pathParameters := map[string]interface{}{
337		"namespaceName":       autorest.Encode("path", namespaceName),
338		"notificationHubName": autorest.Encode("path", notificationHubName),
339		"resourceGroupName":   autorest.Encode("path", resourceGroupName),
340		"subscriptionId":      autorest.Encode("path", client.SubscriptionID),
341	}
342
343	const APIVersion = "2014-09-01"
344	queryParameters := map[string]interface{}{
345		"api-version": APIVersion,
346	}
347
348	preparer := autorest.CreatePreparer(
349		autorest.AsDelete(),
350		autorest.WithBaseURL(client.BaseURI),
351		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NotificationHubs/namespaces/{namespaceName}/notificationHubs/{notificationHubName}", pathParameters),
352		autorest.WithQueryParameters(queryParameters))
353	return preparer.Prepare((&http.Request{}).WithContext(ctx))
354}
355
356// DeleteSender sends the Delete request. The method will close the
357// http.Response Body if it receives an error.
358func (client Client) DeleteSender(req *http.Request) (*http.Response, error) {
359	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
360}
361
362// DeleteResponder handles the response to the Delete request. The method always
363// closes the http.Response Body.
364func (client Client) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
365	err = autorest.Respond(
366		resp,
367		azure.WithErrorUnlessStatusCode(http.StatusOK),
368		autorest.ByClosing())
369	result.Response = resp
370	return
371}
372
373// DeleteAuthorizationRule deletes a notificationHub authorization rule
374// Parameters:
375// resourceGroupName - the name of the resource group.
376// namespaceName - the namespace name.
377// notificationHubName - the notification hub name.
378// authorizationRuleName - authorization Rule Name.
379func (client Client) DeleteAuthorizationRule(ctx context.Context, resourceGroupName string, namespaceName string, notificationHubName string, authorizationRuleName string) (result autorest.Response, err error) {
380	if tracing.IsEnabled() {
381		ctx = tracing.StartSpan(ctx, fqdn+"/Client.DeleteAuthorizationRule")
382		defer func() {
383			sc := -1
384			if result.Response != nil {
385				sc = result.Response.StatusCode
386			}
387			tracing.EndSpan(ctx, sc, err)
388		}()
389	}
390	req, err := client.DeleteAuthorizationRulePreparer(ctx, resourceGroupName, namespaceName, notificationHubName, authorizationRuleName)
391	if err != nil {
392		err = autorest.NewErrorWithError(err, "notificationhubs.Client", "DeleteAuthorizationRule", nil, "Failure preparing request")
393		return
394	}
395
396	resp, err := client.DeleteAuthorizationRuleSender(req)
397	if err != nil {
398		result.Response = resp
399		err = autorest.NewErrorWithError(err, "notificationhubs.Client", "DeleteAuthorizationRule", resp, "Failure sending request")
400		return
401	}
402
403	result, err = client.DeleteAuthorizationRuleResponder(resp)
404	if err != nil {
405		err = autorest.NewErrorWithError(err, "notificationhubs.Client", "DeleteAuthorizationRule", resp, "Failure responding to request")
406		return
407	}
408
409	return
410}
411
412// DeleteAuthorizationRulePreparer prepares the DeleteAuthorizationRule request.
413func (client Client) DeleteAuthorizationRulePreparer(ctx context.Context, resourceGroupName string, namespaceName string, notificationHubName string, authorizationRuleName string) (*http.Request, error) {
414	pathParameters := map[string]interface{}{
415		"authorizationRuleName": autorest.Encode("path", authorizationRuleName),
416		"namespaceName":         autorest.Encode("path", namespaceName),
417		"notificationHubName":   autorest.Encode("path", notificationHubName),
418		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
419		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
420	}
421
422	const APIVersion = "2014-09-01"
423	queryParameters := map[string]interface{}{
424		"api-version": APIVersion,
425	}
426
427	preparer := autorest.CreatePreparer(
428		autorest.AsDelete(),
429		autorest.WithBaseURL(client.BaseURI),
430		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NotificationHubs/namespaces/{namespaceName}/notificationHubs/{notificationHubName}/AuthorizationRules/{authorizationRuleName}", pathParameters),
431		autorest.WithQueryParameters(queryParameters))
432	return preparer.Prepare((&http.Request{}).WithContext(ctx))
433}
434
435// DeleteAuthorizationRuleSender sends the DeleteAuthorizationRule request. The method will close the
436// http.Response Body if it receives an error.
437func (client Client) DeleteAuthorizationRuleSender(req *http.Request) (*http.Response, error) {
438	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
439}
440
441// DeleteAuthorizationRuleResponder handles the response to the DeleteAuthorizationRule request. The method always
442// closes the http.Response Body.
443func (client Client) DeleteAuthorizationRuleResponder(resp *http.Response) (result autorest.Response, err error) {
444	err = autorest.Respond(
445		resp,
446		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
447		autorest.ByClosing())
448	result.Response = resp
449	return
450}
451
452// Get lists the notification hubs associated with a namespace.
453// Parameters:
454// resourceGroupName - the name of the resource group.
455// namespaceName - the namespace name.
456// notificationHubName - the notification hub name.
457func (client Client) Get(ctx context.Context, resourceGroupName string, namespaceName string, notificationHubName string) (result ResourceType, err error) {
458	if tracing.IsEnabled() {
459		ctx = tracing.StartSpan(ctx, fqdn+"/Client.Get")
460		defer func() {
461			sc := -1
462			if result.Response.Response != nil {
463				sc = result.Response.Response.StatusCode
464			}
465			tracing.EndSpan(ctx, sc, err)
466		}()
467	}
468	req, err := client.GetPreparer(ctx, resourceGroupName, namespaceName, notificationHubName)
469	if err != nil {
470		err = autorest.NewErrorWithError(err, "notificationhubs.Client", "Get", nil, "Failure preparing request")
471		return
472	}
473
474	resp, err := client.GetSender(req)
475	if err != nil {
476		result.Response = autorest.Response{Response: resp}
477		err = autorest.NewErrorWithError(err, "notificationhubs.Client", "Get", resp, "Failure sending request")
478		return
479	}
480
481	result, err = client.GetResponder(resp)
482	if err != nil {
483		err = autorest.NewErrorWithError(err, "notificationhubs.Client", "Get", resp, "Failure responding to request")
484		return
485	}
486
487	return
488}
489
490// GetPreparer prepares the Get request.
491func (client Client) GetPreparer(ctx context.Context, resourceGroupName string, namespaceName string, notificationHubName string) (*http.Request, error) {
492	pathParameters := map[string]interface{}{
493		"namespaceName":       autorest.Encode("path", namespaceName),
494		"notificationHubName": autorest.Encode("path", notificationHubName),
495		"resourceGroupName":   autorest.Encode("path", resourceGroupName),
496		"subscriptionId":      autorest.Encode("path", client.SubscriptionID),
497	}
498
499	const APIVersion = "2014-09-01"
500	queryParameters := map[string]interface{}{
501		"api-version": APIVersion,
502	}
503
504	preparer := autorest.CreatePreparer(
505		autorest.AsGet(),
506		autorest.WithBaseURL(client.BaseURI),
507		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NotificationHubs/namespaces/{namespaceName}/notificationHubs/{notificationHubName}", pathParameters),
508		autorest.WithQueryParameters(queryParameters))
509	return preparer.Prepare((&http.Request{}).WithContext(ctx))
510}
511
512// GetSender sends the Get request. The method will close the
513// http.Response Body if it receives an error.
514func (client Client) GetSender(req *http.Request) (*http.Response, error) {
515	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
516}
517
518// GetResponder handles the response to the Get request. The method always
519// closes the http.Response Body.
520func (client Client) GetResponder(resp *http.Response) (result ResourceType, err error) {
521	err = autorest.Respond(
522		resp,
523		azure.WithErrorUnlessStatusCode(http.StatusOK),
524		autorest.ByUnmarshallingJSON(&result),
525		autorest.ByClosing())
526	result.Response = autorest.Response{Response: resp}
527	return
528}
529
530// GetAuthorizationRule gets an authorization rule for a NotificationHub by name.
531// Parameters:
532// resourceGroupName - the name of the resource group.
533// namespaceName - the namespace name
534// notificationHubName - the notification hub name.
535// authorizationRuleName - authorization rule name.
536func (client Client) GetAuthorizationRule(ctx context.Context, resourceGroupName string, namespaceName string, notificationHubName string, authorizationRuleName string) (result SharedAccessAuthorizationRuleResource, err error) {
537	if tracing.IsEnabled() {
538		ctx = tracing.StartSpan(ctx, fqdn+"/Client.GetAuthorizationRule")
539		defer func() {
540			sc := -1
541			if result.Response.Response != nil {
542				sc = result.Response.Response.StatusCode
543			}
544			tracing.EndSpan(ctx, sc, err)
545		}()
546	}
547	req, err := client.GetAuthorizationRulePreparer(ctx, resourceGroupName, namespaceName, notificationHubName, authorizationRuleName)
548	if err != nil {
549		err = autorest.NewErrorWithError(err, "notificationhubs.Client", "GetAuthorizationRule", nil, "Failure preparing request")
550		return
551	}
552
553	resp, err := client.GetAuthorizationRuleSender(req)
554	if err != nil {
555		result.Response = autorest.Response{Response: resp}
556		err = autorest.NewErrorWithError(err, "notificationhubs.Client", "GetAuthorizationRule", resp, "Failure sending request")
557		return
558	}
559
560	result, err = client.GetAuthorizationRuleResponder(resp)
561	if err != nil {
562		err = autorest.NewErrorWithError(err, "notificationhubs.Client", "GetAuthorizationRule", resp, "Failure responding to request")
563		return
564	}
565
566	return
567}
568
569// GetAuthorizationRulePreparer prepares the GetAuthorizationRule request.
570func (client Client) GetAuthorizationRulePreparer(ctx context.Context, resourceGroupName string, namespaceName string, notificationHubName string, authorizationRuleName string) (*http.Request, error) {
571	pathParameters := map[string]interface{}{
572		"authorizationRuleName": autorest.Encode("path", authorizationRuleName),
573		"namespaceName":         autorest.Encode("path", namespaceName),
574		"notificationHubName":   autorest.Encode("path", notificationHubName),
575		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
576		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
577	}
578
579	const APIVersion = "2014-09-01"
580	queryParameters := map[string]interface{}{
581		"api-version": APIVersion,
582	}
583
584	preparer := autorest.CreatePreparer(
585		autorest.AsPost(),
586		autorest.WithBaseURL(client.BaseURI),
587		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NotificationHubs/namespaces/{namespaceName}/notificationHubs/{notificationHubName}/AuthorizationRules/{authorizationRuleName}", pathParameters),
588		autorest.WithQueryParameters(queryParameters))
589	return preparer.Prepare((&http.Request{}).WithContext(ctx))
590}
591
592// GetAuthorizationRuleSender sends the GetAuthorizationRule request. The method will close the
593// http.Response Body if it receives an error.
594func (client Client) GetAuthorizationRuleSender(req *http.Request) (*http.Response, error) {
595	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
596}
597
598// GetAuthorizationRuleResponder handles the response to the GetAuthorizationRule request. The method always
599// closes the http.Response Body.
600func (client Client) GetAuthorizationRuleResponder(resp *http.Response) (result SharedAccessAuthorizationRuleResource, err error) {
601	err = autorest.Respond(
602		resp,
603		azure.WithErrorUnlessStatusCode(http.StatusOK),
604		autorest.ByUnmarshallingJSON(&result),
605		autorest.ByClosing())
606	result.Response = autorest.Response{Response: resp}
607	return
608}
609
610// GetPnsCredentials lists the PNS Credentials associated with a notification hub .
611// Parameters:
612// resourceGroupName - the name of the resource group.
613// namespaceName - the namespace name.
614// notificationHubName - the notification hub name.
615func (client Client) GetPnsCredentials(ctx context.Context, resourceGroupName string, namespaceName string, notificationHubName string) (result ResourceType, err error) {
616	if tracing.IsEnabled() {
617		ctx = tracing.StartSpan(ctx, fqdn+"/Client.GetPnsCredentials")
618		defer func() {
619			sc := -1
620			if result.Response.Response != nil {
621				sc = result.Response.Response.StatusCode
622			}
623			tracing.EndSpan(ctx, sc, err)
624		}()
625	}
626	req, err := client.GetPnsCredentialsPreparer(ctx, resourceGroupName, namespaceName, notificationHubName)
627	if err != nil {
628		err = autorest.NewErrorWithError(err, "notificationhubs.Client", "GetPnsCredentials", nil, "Failure preparing request")
629		return
630	}
631
632	resp, err := client.GetPnsCredentialsSender(req)
633	if err != nil {
634		result.Response = autorest.Response{Response: resp}
635		err = autorest.NewErrorWithError(err, "notificationhubs.Client", "GetPnsCredentials", resp, "Failure sending request")
636		return
637	}
638
639	result, err = client.GetPnsCredentialsResponder(resp)
640	if err != nil {
641		err = autorest.NewErrorWithError(err, "notificationhubs.Client", "GetPnsCredentials", resp, "Failure responding to request")
642		return
643	}
644
645	return
646}
647
648// GetPnsCredentialsPreparer prepares the GetPnsCredentials request.
649func (client Client) GetPnsCredentialsPreparer(ctx context.Context, resourceGroupName string, namespaceName string, notificationHubName string) (*http.Request, error) {
650	pathParameters := map[string]interface{}{
651		"namespaceName":       autorest.Encode("path", namespaceName),
652		"notificationHubName": autorest.Encode("path", notificationHubName),
653		"resourceGroupName":   autorest.Encode("path", resourceGroupName),
654		"subscriptionId":      autorest.Encode("path", client.SubscriptionID),
655	}
656
657	const APIVersion = "2014-09-01"
658	queryParameters := map[string]interface{}{
659		"api-version": APIVersion,
660	}
661
662	preparer := autorest.CreatePreparer(
663		autorest.AsPost(),
664		autorest.WithBaseURL(client.BaseURI),
665		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NotificationHubs/namespaces/{namespaceName}/notificationHubs/{notificationHubName}/pnsCredentials", pathParameters),
666		autorest.WithQueryParameters(queryParameters))
667	return preparer.Prepare((&http.Request{}).WithContext(ctx))
668}
669
670// GetPnsCredentialsSender sends the GetPnsCredentials request. The method will close the
671// http.Response Body if it receives an error.
672func (client Client) GetPnsCredentialsSender(req *http.Request) (*http.Response, error) {
673	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
674}
675
676// GetPnsCredentialsResponder handles the response to the GetPnsCredentials request. The method always
677// closes the http.Response Body.
678func (client Client) GetPnsCredentialsResponder(resp *http.Response) (result ResourceType, err error) {
679	err = autorest.Respond(
680		resp,
681		azure.WithErrorUnlessStatusCode(http.StatusOK),
682		autorest.ByUnmarshallingJSON(&result),
683		autorest.ByClosing())
684	result.Response = autorest.Response{Response: resp}
685	return
686}
687
688// List lists the notification hubs associated with a namespace.
689// Parameters:
690// resourceGroupName - the name of the resource group.
691// namespaceName - the namespace name.
692func (client Client) List(ctx context.Context, resourceGroupName string, namespaceName string) (result ListResultPage, err error) {
693	if tracing.IsEnabled() {
694		ctx = tracing.StartSpan(ctx, fqdn+"/Client.List")
695		defer func() {
696			sc := -1
697			if result.lr.Response.Response != nil {
698				sc = result.lr.Response.Response.StatusCode
699			}
700			tracing.EndSpan(ctx, sc, err)
701		}()
702	}
703	result.fn = client.listNextResults
704	req, err := client.ListPreparer(ctx, resourceGroupName, namespaceName)
705	if err != nil {
706		err = autorest.NewErrorWithError(err, "notificationhubs.Client", "List", nil, "Failure preparing request")
707		return
708	}
709
710	resp, err := client.ListSender(req)
711	if err != nil {
712		result.lr.Response = autorest.Response{Response: resp}
713		err = autorest.NewErrorWithError(err, "notificationhubs.Client", "List", resp, "Failure sending request")
714		return
715	}
716
717	result.lr, err = client.ListResponder(resp)
718	if err != nil {
719		err = autorest.NewErrorWithError(err, "notificationhubs.Client", "List", resp, "Failure responding to request")
720		return
721	}
722	if result.lr.hasNextLink() && result.lr.IsEmpty() {
723		err = result.NextWithContext(ctx)
724		return
725	}
726
727	return
728}
729
730// ListPreparer prepares the List request.
731func (client Client) ListPreparer(ctx context.Context, resourceGroupName string, namespaceName string) (*http.Request, error) {
732	pathParameters := map[string]interface{}{
733		"namespaceName":     autorest.Encode("path", namespaceName),
734		"resourceGroupName": autorest.Encode("path", resourceGroupName),
735		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
736	}
737
738	const APIVersion = "2014-09-01"
739	queryParameters := map[string]interface{}{
740		"api-version": APIVersion,
741	}
742
743	preparer := autorest.CreatePreparer(
744		autorest.AsGet(),
745		autorest.WithBaseURL(client.BaseURI),
746		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NotificationHubs/namespaces/{namespaceName}/notificationHubs", pathParameters),
747		autorest.WithQueryParameters(queryParameters))
748	return preparer.Prepare((&http.Request{}).WithContext(ctx))
749}
750
751// ListSender sends the List request. The method will close the
752// http.Response Body if it receives an error.
753func (client Client) ListSender(req *http.Request) (*http.Response, error) {
754	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
755}
756
757// ListResponder handles the response to the List request. The method always
758// closes the http.Response Body.
759func (client Client) ListResponder(resp *http.Response) (result ListResult, err error) {
760	err = autorest.Respond(
761		resp,
762		azure.WithErrorUnlessStatusCode(http.StatusOK),
763		autorest.ByUnmarshallingJSON(&result),
764		autorest.ByClosing())
765	result.Response = autorest.Response{Response: resp}
766	return
767}
768
769// listNextResults retrieves the next set of results, if any.
770func (client Client) listNextResults(ctx context.Context, lastResults ListResult) (result ListResult, err error) {
771	req, err := lastResults.listResultPreparer(ctx)
772	if err != nil {
773		return result, autorest.NewErrorWithError(err, "notificationhubs.Client", "listNextResults", nil, "Failure preparing next results request")
774	}
775	if req == nil {
776		return
777	}
778	resp, err := client.ListSender(req)
779	if err != nil {
780		result.Response = autorest.Response{Response: resp}
781		return result, autorest.NewErrorWithError(err, "notificationhubs.Client", "listNextResults", resp, "Failure sending next results request")
782	}
783	result, err = client.ListResponder(resp)
784	if err != nil {
785		err = autorest.NewErrorWithError(err, "notificationhubs.Client", "listNextResults", resp, "Failure responding to next results request")
786	}
787	return
788}
789
790// ListComplete enumerates all values, automatically crossing page boundaries as required.
791func (client Client) ListComplete(ctx context.Context, resourceGroupName string, namespaceName string) (result ListResultIterator, err error) {
792	if tracing.IsEnabled() {
793		ctx = tracing.StartSpan(ctx, fqdn+"/Client.List")
794		defer func() {
795			sc := -1
796			if result.Response().Response.Response != nil {
797				sc = result.page.Response().Response.Response.StatusCode
798			}
799			tracing.EndSpan(ctx, sc, err)
800		}()
801	}
802	result.page, err = client.List(ctx, resourceGroupName, namespaceName)
803	return
804}
805
806// ListAuthorizationRules gets the authorization rules for a NotificationHub.
807// Parameters:
808// resourceGroupName - the name of the resource group.
809// namespaceName - the namespace name
810// notificationHubName - the notification hub name.
811func (client Client) ListAuthorizationRules(ctx context.Context, resourceGroupName string, namespaceName string, notificationHubName string) (result SharedAccessAuthorizationRuleListResultPage, err error) {
812	if tracing.IsEnabled() {
813		ctx = tracing.StartSpan(ctx, fqdn+"/Client.ListAuthorizationRules")
814		defer func() {
815			sc := -1
816			if result.saarlr.Response.Response != nil {
817				sc = result.saarlr.Response.Response.StatusCode
818			}
819			tracing.EndSpan(ctx, sc, err)
820		}()
821	}
822	result.fn = client.listAuthorizationRulesNextResults
823	req, err := client.ListAuthorizationRulesPreparer(ctx, resourceGroupName, namespaceName, notificationHubName)
824	if err != nil {
825		err = autorest.NewErrorWithError(err, "notificationhubs.Client", "ListAuthorizationRules", nil, "Failure preparing request")
826		return
827	}
828
829	resp, err := client.ListAuthorizationRulesSender(req)
830	if err != nil {
831		result.saarlr.Response = autorest.Response{Response: resp}
832		err = autorest.NewErrorWithError(err, "notificationhubs.Client", "ListAuthorizationRules", resp, "Failure sending request")
833		return
834	}
835
836	result.saarlr, err = client.ListAuthorizationRulesResponder(resp)
837	if err != nil {
838		err = autorest.NewErrorWithError(err, "notificationhubs.Client", "ListAuthorizationRules", resp, "Failure responding to request")
839		return
840	}
841	if result.saarlr.hasNextLink() && result.saarlr.IsEmpty() {
842		err = result.NextWithContext(ctx)
843		return
844	}
845
846	return
847}
848
849// ListAuthorizationRulesPreparer prepares the ListAuthorizationRules request.
850func (client Client) ListAuthorizationRulesPreparer(ctx context.Context, resourceGroupName string, namespaceName string, notificationHubName string) (*http.Request, error) {
851	pathParameters := map[string]interface{}{
852		"namespaceName":       autorest.Encode("path", namespaceName),
853		"notificationHubName": autorest.Encode("path", notificationHubName),
854		"resourceGroupName":   autorest.Encode("path", resourceGroupName),
855		"subscriptionId":      autorest.Encode("path", client.SubscriptionID),
856	}
857
858	const APIVersion = "2014-09-01"
859	queryParameters := map[string]interface{}{
860		"api-version": APIVersion,
861	}
862
863	preparer := autorest.CreatePreparer(
864		autorest.AsPost(),
865		autorest.WithBaseURL(client.BaseURI),
866		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NotificationHubs/namespaces/{namespaceName}/notificationHubs/{notificationHubName}/AuthorizationRules", pathParameters),
867		autorest.WithQueryParameters(queryParameters))
868	return preparer.Prepare((&http.Request{}).WithContext(ctx))
869}
870
871// ListAuthorizationRulesSender sends the ListAuthorizationRules request. The method will close the
872// http.Response Body if it receives an error.
873func (client Client) ListAuthorizationRulesSender(req *http.Request) (*http.Response, error) {
874	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
875}
876
877// ListAuthorizationRulesResponder handles the response to the ListAuthorizationRules request. The method always
878// closes the http.Response Body.
879func (client Client) ListAuthorizationRulesResponder(resp *http.Response) (result SharedAccessAuthorizationRuleListResult, err error) {
880	err = autorest.Respond(
881		resp,
882		azure.WithErrorUnlessStatusCode(http.StatusOK),
883		autorest.ByUnmarshallingJSON(&result),
884		autorest.ByClosing())
885	result.Response = autorest.Response{Response: resp}
886	return
887}
888
889// listAuthorizationRulesNextResults retrieves the next set of results, if any.
890func (client Client) listAuthorizationRulesNextResults(ctx context.Context, lastResults SharedAccessAuthorizationRuleListResult) (result SharedAccessAuthorizationRuleListResult, err error) {
891	req, err := lastResults.sharedAccessAuthorizationRuleListResultPreparer(ctx)
892	if err != nil {
893		return result, autorest.NewErrorWithError(err, "notificationhubs.Client", "listAuthorizationRulesNextResults", nil, "Failure preparing next results request")
894	}
895	if req == nil {
896		return
897	}
898	resp, err := client.ListAuthorizationRulesSender(req)
899	if err != nil {
900		result.Response = autorest.Response{Response: resp}
901		return result, autorest.NewErrorWithError(err, "notificationhubs.Client", "listAuthorizationRulesNextResults", resp, "Failure sending next results request")
902	}
903	result, err = client.ListAuthorizationRulesResponder(resp)
904	if err != nil {
905		err = autorest.NewErrorWithError(err, "notificationhubs.Client", "listAuthorizationRulesNextResults", resp, "Failure responding to next results request")
906	}
907	return
908}
909
910// ListAuthorizationRulesComplete enumerates all values, automatically crossing page boundaries as required.
911func (client Client) ListAuthorizationRulesComplete(ctx context.Context, resourceGroupName string, namespaceName string, notificationHubName string) (result SharedAccessAuthorizationRuleListResultIterator, err error) {
912	if tracing.IsEnabled() {
913		ctx = tracing.StartSpan(ctx, fqdn+"/Client.ListAuthorizationRules")
914		defer func() {
915			sc := -1
916			if result.Response().Response.Response != nil {
917				sc = result.page.Response().Response.Response.StatusCode
918			}
919			tracing.EndSpan(ctx, sc, err)
920		}()
921	}
922	result.page, err = client.ListAuthorizationRules(ctx, resourceGroupName, namespaceName, notificationHubName)
923	return
924}
925
926// ListKeys gets the Primary and Secondary ConnectionStrings to the NotificationHub
927// Parameters:
928// resourceGroupName - the name of the resource group.
929// namespaceName - the namespace name.
930// notificationHubName - the notification hub name.
931// authorizationRuleName - the connection string of the NotificationHub for the specified authorizationRule.
932func (client Client) ListKeys(ctx context.Context, resourceGroupName string, namespaceName string, notificationHubName string, authorizationRuleName string) (result ResourceListKeys, err error) {
933	if tracing.IsEnabled() {
934		ctx = tracing.StartSpan(ctx, fqdn+"/Client.ListKeys")
935		defer func() {
936			sc := -1
937			if result.Response.Response != nil {
938				sc = result.Response.Response.StatusCode
939			}
940			tracing.EndSpan(ctx, sc, err)
941		}()
942	}
943	req, err := client.ListKeysPreparer(ctx, resourceGroupName, namespaceName, notificationHubName, authorizationRuleName)
944	if err != nil {
945		err = autorest.NewErrorWithError(err, "notificationhubs.Client", "ListKeys", nil, "Failure preparing request")
946		return
947	}
948
949	resp, err := client.ListKeysSender(req)
950	if err != nil {
951		result.Response = autorest.Response{Response: resp}
952		err = autorest.NewErrorWithError(err, "notificationhubs.Client", "ListKeys", resp, "Failure sending request")
953		return
954	}
955
956	result, err = client.ListKeysResponder(resp)
957	if err != nil {
958		err = autorest.NewErrorWithError(err, "notificationhubs.Client", "ListKeys", resp, "Failure responding to request")
959		return
960	}
961
962	return
963}
964
965// ListKeysPreparer prepares the ListKeys request.
966func (client Client) ListKeysPreparer(ctx context.Context, resourceGroupName string, namespaceName string, notificationHubName string, authorizationRuleName string) (*http.Request, error) {
967	pathParameters := map[string]interface{}{
968		"authorizationRuleName": autorest.Encode("path", authorizationRuleName),
969		"namespaceName":         autorest.Encode("path", namespaceName),
970		"notificationHubName":   autorest.Encode("path", notificationHubName),
971		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
972		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
973	}
974
975	const APIVersion = "2014-09-01"
976	queryParameters := map[string]interface{}{
977		"api-version": APIVersion,
978	}
979
980	preparer := autorest.CreatePreparer(
981		autorest.AsPost(),
982		autorest.WithBaseURL(client.BaseURI),
983		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NotificationHubs/namespaces/{namespaceName}/notificationHubs/{notificationHubName}/AuthorizationRules/{authorizationRuleName}/listKeys", pathParameters),
984		autorest.WithQueryParameters(queryParameters))
985	return preparer.Prepare((&http.Request{}).WithContext(ctx))
986}
987
988// ListKeysSender sends the ListKeys request. The method will close the
989// http.Response Body if it receives an error.
990func (client Client) ListKeysSender(req *http.Request) (*http.Response, error) {
991	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
992}
993
994// ListKeysResponder handles the response to the ListKeys request. The method always
995// closes the http.Response Body.
996func (client Client) ListKeysResponder(resp *http.Response) (result ResourceListKeys, err error) {
997	err = autorest.Respond(
998		resp,
999		azure.WithErrorUnlessStatusCode(http.StatusOK),
1000		autorest.ByUnmarshallingJSON(&result),
1001		autorest.ByClosing())
1002	result.Response = autorest.Response{Response: resp}
1003	return
1004}
1005