diff --git a/profiles/latest/notificationhubs/mgmt/notificationhubs/models.go b/profiles/latest/notificationhubs/mgmt/notificationhubs/models.go index 887270844d81..784a0f2c5279 100644 --- a/profiles/latest/notificationhubs/mgmt/notificationhubs/models.go +++ b/profiles/latest/notificationhubs/mgmt/notificationhubs/models.go @@ -58,6 +58,8 @@ type BaiduCredentialProperties = original.BaiduCredentialProperties type CheckAvailabilityParameters = original.CheckAvailabilityParameters type CheckAvailabilityResult = original.CheckAvailabilityResult type CreateOrUpdateParameters = original.CreateOrUpdateParameters +type DebugSendResponse = original.DebugSendResponse +type DebugSendResult = original.DebugSendResult type ErrorResponse = original.ErrorResponse type GcmCredential = original.GcmCredential type GcmCredentialProperties = original.GcmCredentialProperties @@ -79,6 +81,7 @@ type OperationDisplay = original.OperationDisplay type OperationListResult = original.OperationListResult type OperationListResultIterator = original.OperationListResultIterator type OperationListResultPage = original.OperationListResultPage +type PatchParameters = original.PatchParameters type PnsCredentialsProperties = original.PnsCredentialsProperties type PnsCredentialsResource = original.PnsCredentialsResource type PolicykeyResource = original.PolicykeyResource diff --git a/profiles/preview/notificationhubs/mgmt/notificationhubs/models.go b/profiles/preview/notificationhubs/mgmt/notificationhubs/models.go index 3e8fbef3a334..0926470465c7 100644 --- a/profiles/preview/notificationhubs/mgmt/notificationhubs/models.go +++ b/profiles/preview/notificationhubs/mgmt/notificationhubs/models.go @@ -58,6 +58,8 @@ type BaiduCredentialProperties = original.BaiduCredentialProperties type CheckAvailabilityParameters = original.CheckAvailabilityParameters type CheckAvailabilityResult = original.CheckAvailabilityResult type CreateOrUpdateParameters = original.CreateOrUpdateParameters +type DebugSendResponse = original.DebugSendResponse +type DebugSendResult = original.DebugSendResult type ErrorResponse = original.ErrorResponse type GcmCredential = original.GcmCredential type GcmCredentialProperties = original.GcmCredentialProperties @@ -79,6 +81,7 @@ type OperationDisplay = original.OperationDisplay type OperationListResult = original.OperationListResult type OperationListResultIterator = original.OperationListResultIterator type OperationListResultPage = original.OperationListResultPage +type PatchParameters = original.PatchParameters type PnsCredentialsProperties = original.PnsCredentialsProperties type PnsCredentialsResource = original.PnsCredentialsResource type PolicykeyResource = original.PolicykeyResource diff --git a/services/notificationhubs/mgmt/2017-04-01/notificationhubs/models.go b/services/notificationhubs/mgmt/2017-04-01/notificationhubs/models.go index 06e9cbb754b0..82520f63cce1 100644 --- a/services/notificationhubs/mgmt/2017-04-01/notificationhubs/models.go +++ b/services/notificationhubs/mgmt/2017-04-01/notificationhubs/models.go @@ -447,6 +447,140 @@ func (coup *CreateOrUpdateParameters) UnmarshalJSON(body []byte) error { return nil } +// DebugSendResponse description of a NotificationHub Resource. +type DebugSendResponse struct { + autorest.Response `json:"-"` + // DebugSendResult - Properties of the NotificationHub. + *DebugSendResult `json:"properties,omitempty"` + // ID - Resource Id + ID *string `json:"id,omitempty"` + // Name - Resource name + Name *string `json:"name,omitempty"` + // Type - Resource type + Type *string `json:"type,omitempty"` + // Location - Resource location + Location *string `json:"location,omitempty"` + // Tags - Resource tags + Tags map[string]*string `json:"tags"` + // Sku - The sku of the created namespace + Sku *Sku `json:"sku,omitempty"` +} + +// MarshalJSON is the custom marshaler for DebugSendResponse. +func (dsr DebugSendResponse) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if dsr.DebugSendResult != nil { + objectMap["properties"] = dsr.DebugSendResult + } + if dsr.ID != nil { + objectMap["id"] = dsr.ID + } + if dsr.Name != nil { + objectMap["name"] = dsr.Name + } + if dsr.Type != nil { + objectMap["type"] = dsr.Type + } + if dsr.Location != nil { + objectMap["location"] = dsr.Location + } + if dsr.Tags != nil { + objectMap["tags"] = dsr.Tags + } + if dsr.Sku != nil { + objectMap["sku"] = dsr.Sku + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for DebugSendResponse struct. +func (dsr *DebugSendResponse) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "properties": + if v != nil { + var debugSendResult DebugSendResult + err = json.Unmarshal(*v, &debugSendResult) + if err != nil { + return err + } + dsr.DebugSendResult = &debugSendResult + } + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + dsr.ID = &ID + } + case "name": + if v != nil { + var name string + err = json.Unmarshal(*v, &name) + if err != nil { + return err + } + dsr.Name = &name + } + case "type": + if v != nil { + var typeVar string + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + dsr.Type = &typeVar + } + case "location": + if v != nil { + var location string + err = json.Unmarshal(*v, &location) + if err != nil { + return err + } + dsr.Location = &location + } + case "tags": + if v != nil { + var tags map[string]*string + err = json.Unmarshal(*v, &tags) + if err != nil { + return err + } + dsr.Tags = tags + } + case "sku": + if v != nil { + var sku Sku + err = json.Unmarshal(*v, &sku) + if err != nil { + return err + } + dsr.Sku = &sku + } + } + } + + return nil +} + +// DebugSendResult ... +type DebugSendResult struct { + // Success - successful send + Success *float64 `json:"success,omitempty"` + // Failure - send failure + Failure *float64 `json:"failure,omitempty"` + // Results - actual failure description + Results interface{} `json:"results,omitempty"` +} + // ErrorResponse error reponse indicates NotificationHubs service is not able to process the incoming request. The // reason is provided in the error message. type ErrorResponse struct { @@ -1198,6 +1332,129 @@ func (page OperationListResultPage) Values() []Operation { return *page.olr.Value } +// PatchParameters parameters supplied to the patch NotificationHub operation. +type PatchParameters struct { + // Properties - Properties of the NotificationHub. + *Properties `json:"properties,omitempty"` + // ID - Resource Id + ID *string `json:"id,omitempty"` + // Name - Resource name + Name *string `json:"name,omitempty"` + // Type - Resource type + Type *string `json:"type,omitempty"` + // Location - Resource location + Location *string `json:"location,omitempty"` + // Tags - Resource tags + Tags map[string]*string `json:"tags"` + // Sku - The sku of the created namespace + Sku *Sku `json:"sku,omitempty"` +} + +// MarshalJSON is the custom marshaler for PatchParameters. +func (pp PatchParameters) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if pp.Properties != nil { + objectMap["properties"] = pp.Properties + } + if pp.ID != nil { + objectMap["id"] = pp.ID + } + if pp.Name != nil { + objectMap["name"] = pp.Name + } + if pp.Type != nil { + objectMap["type"] = pp.Type + } + if pp.Location != nil { + objectMap["location"] = pp.Location + } + if pp.Tags != nil { + objectMap["tags"] = pp.Tags + } + if pp.Sku != nil { + objectMap["sku"] = pp.Sku + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for PatchParameters struct. +func (pp *PatchParameters) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "properties": + if v != nil { + var properties Properties + err = json.Unmarshal(*v, &properties) + if err != nil { + return err + } + pp.Properties = &properties + } + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + pp.ID = &ID + } + case "name": + if v != nil { + var name string + err = json.Unmarshal(*v, &name) + if err != nil { + return err + } + pp.Name = &name + } + case "type": + if v != nil { + var typeVar string + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + pp.Type = &typeVar + } + case "location": + if v != nil { + var location string + err = json.Unmarshal(*v, &location) + if err != nil { + return err + } + pp.Location = &location + } + case "tags": + if v != nil { + var tags map[string]*string + err = json.Unmarshal(*v, &tags) + if err != nil { + return err + } + pp.Tags = tags + } + case "sku": + if v != nil { + var sku Sku + err = json.Unmarshal(*v, &sku) + if err != nil { + return err + } + pp.Sku = &sku + } + } + } + + return nil +} + // PnsCredentialsProperties description of a NotificationHub PNS Credentials. type PnsCredentialsProperties struct { // ApnsCredential - The ApnsCredential of the created NotificationHub diff --git a/services/notificationhubs/mgmt/2017-04-01/notificationhubs/namespaces.go b/services/notificationhubs/mgmt/2017-04-01/notificationhubs/namespaces.go index c14964081ac9..e7362a7a0a89 100644 --- a/services/notificationhubs/mgmt/2017-04-01/notificationhubs/namespaces.go +++ b/services/notificationhubs/mgmt/2017-04-01/notificationhubs/namespaces.go @@ -47,8 +47,7 @@ func NewNamespacesClientWithBaseURI(baseURI string, subscriptionID string) Names func (client NamespacesClient) CheckAvailability(ctx context.Context, parameters CheckAvailabilityParameters) (result CheckAvailabilityResult, err error) { if err := validation.Validate([]validation.Validation{ {TargetValue: parameters, - Constraints: []validation.Constraint{{Target: "parameters.Name", Name: validation.Null, Rule: true, Chain: nil}, - {Target: "parameters.Location", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { + Constraints: []validation.Constraint{{Target: "parameters.Name", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { return result, validation.NewError("notificationhubs.NamespacesClient", "CheckAvailability", err.Error()) } diff --git a/services/notificationhubs/mgmt/2017-04-01/notificationhubs/notificationhubs.go b/services/notificationhubs/mgmt/2017-04-01/notificationhubs/notificationhubs.go index 736636e46a45..29e1e678beb3 100644 --- a/services/notificationhubs/mgmt/2017-04-01/notificationhubs/notificationhubs.go +++ b/services/notificationhubs/mgmt/2017-04-01/notificationhubs/notificationhubs.go @@ -48,8 +48,7 @@ func NewClientWithBaseURI(baseURI string, subscriptionID string) Client { func (client Client) CheckNotificationHubAvailability(ctx context.Context, resourceGroupName string, namespaceName string, parameters CheckAvailabilityParameters) (result CheckAvailabilityResult, err error) { if err := validation.Validate([]validation.Validation{ {TargetValue: parameters, - Constraints: []validation.Constraint{{Target: "parameters.Name", Name: validation.Null, Rule: true, Chain: nil}, - {Target: "parameters.Location", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { + Constraints: []validation.Constraint{{Target: "parameters.Name", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { return result, validation.NewError("notificationhubs.Client", "CheckNotificationHubAvailability", err.Error()) } @@ -275,6 +274,81 @@ func (client Client) CreateOrUpdateAuthorizationRuleResponder(resp *http.Respons return } +// DebugSend test send a push notification +// Parameters: +// resourceGroupName - the name of the resource group. +// namespaceName - the namespace name. +// notificationHubName - the notification hub name. +// parameters - debug send parameters +func (client Client) DebugSend(ctx context.Context, resourceGroupName string, namespaceName string, notificationHubName string, parameters *interface{}) (result DebugSendResponse, err error) { + req, err := client.DebugSendPreparer(ctx, resourceGroupName, namespaceName, notificationHubName, parameters) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.Client", "DebugSend", nil, "Failure preparing request") + return + } + + resp, err := client.DebugSendSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "notificationhubs.Client", "DebugSend", resp, "Failure sending request") + return + } + + result, err = client.DebugSendResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.Client", "DebugSend", resp, "Failure responding to request") + } + + return +} + +// DebugSendPreparer prepares the DebugSend request. +func (client Client) DebugSendPreparer(ctx context.Context, resourceGroupName string, namespaceName string, notificationHubName string, parameters *interface{}) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "namespaceName": autorest.Encode("path", namespaceName), + "notificationHubName": autorest.Encode("path", notificationHubName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-04-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NotificationHubs/namespaces/{namespaceName}/notificationHubs/{notificationHubName}/debugsend", pathParameters), + autorest.WithQueryParameters(queryParameters)) + if parameters != nil { + preparer = autorest.DecoratePreparer(preparer, + autorest.WithJSON(parameters)) + } + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// DebugSendSender sends the DebugSend request. The method will close the +// http.Response Body if it receives an error. +func (client Client) DebugSendSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// DebugSendResponder handles the response to the DebugSend request. The method always +// closes the http.Response Body. +func (client Client) DebugSendResponder(resp *http.Response) (result DebugSendResponse, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + // Delete deletes a notification hub associated with a namespace. // Parameters: // resourceGroupName - the name of the resource group. @@ -885,6 +959,81 @@ func (client Client) ListKeysResponder(resp *http.Response) (result ResourceList return } +// Patch patch a NotificationHub in a namespace. +// Parameters: +// resourceGroupName - the name of the resource group. +// namespaceName - the namespace name. +// notificationHubName - the notification hub name. +// parameters - parameters supplied to patch a NotificationHub Resource. +func (client Client) Patch(ctx context.Context, resourceGroupName string, namespaceName string, notificationHubName string, parameters *PatchParameters) (result ResourceType, err error) { + req, err := client.PatchPreparer(ctx, resourceGroupName, namespaceName, notificationHubName, parameters) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.Client", "Patch", nil, "Failure preparing request") + return + } + + resp, err := client.PatchSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "notificationhubs.Client", "Patch", resp, "Failure sending request") + return + } + + result, err = client.PatchResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.Client", "Patch", resp, "Failure responding to request") + } + + return +} + +// PatchPreparer prepares the Patch request. +func (client Client) PatchPreparer(ctx context.Context, resourceGroupName string, namespaceName string, notificationHubName string, parameters *PatchParameters) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "namespaceName": autorest.Encode("path", namespaceName), + "notificationHubName": autorest.Encode("path", notificationHubName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-04-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPatch(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NotificationHubs/namespaces/{namespaceName}/notificationHubs/{notificationHubName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + if parameters != nil { + preparer = autorest.DecoratePreparer(preparer, + autorest.WithJSON(parameters)) + } + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// PatchSender sends the Patch request. The method will close the +// http.Response Body if it receives an error. +func (client Client) PatchSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// PatchResponder handles the response to the Patch request. The method always +// closes the http.Response Body. +func (client Client) PatchResponder(resp *http.Response) (result ResourceType, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + // RegenerateKeys regenerates the Primary/Secondary Keys to the NotificationHub Authorization Rule // Parameters: // resourceGroupName - the name of the resource group.