Exemplo n.º 1
0
        /// <summary>
        /// Register new webhook for incoming subscriptions.
        /// </summary>
        /// <param name="webhook"><see cref="Webhook"/></param>
        /// <example>
        /// <code>
        /// try
        /// {
        ///     var webhook = new Webhook
        ///     {
        ///         Url = "www.exampleurl.com",
        ///     };
        ///     connectApi.UpdateWebhook(webhook);
        /// }
        /// catch (CloudApiException)
        /// {
        ///     throw;
        /// }
        /// </code>
        /// </example>
        /// <exception cref="CloudApiException">CloudApiException</exception>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        public async Task UpdateWebhookAsync(Webhook webhook)
        {
            if (DeliveryMethod == null)
            {
                DeliveryMethod = NotificationDeliveryMethod.DeliveryMethod.SERVER_INITIATED;
            }

            if (DeliveryMethod == NotificationDeliveryMethod.DeliveryMethod.CLIENT_INITIATED)
            {
                throw new CloudApiException(400, "cannot update webhook when delivery method is Client Initiated");
            }

            try
            {
                if (forceClear)
                {
                    await StopNotificationsAsync();
                }

                var currentWebhook = GetWebhook();

                if (currentWebhook.Url != webhook.Url)
                {
                    await NotificationsApi.RegisterWebhookAsync(Webhook.MapToApiWebook(webhook));
                }
            }
            catch (mds.Client.ApiException ex)
            {
                throw new CloudApiException(ex.ErrorCode, ex.Message, ex.ErrorContent);
            }
        }