/// <inheritdoc/>
        public Task UpdateWebhookAsync(ScalingGroupId groupId, PolicyId policyId, WebhookId webhookId, UpdateWebhookConfiguration configuration, CancellationToken cancellationToken)
        {
            if (groupId == null)
            {
                throw new ArgumentNullException("groupId");
            }
            if (policyId == null)
            {
                throw new ArgumentNullException("policyId");
            }
            if (webhookId == null)
            {
                throw new ArgumentNullException("webhookId");
            }
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            UriTemplate template   = new UriTemplate("/groups/{groupId}/policies/{policyId}/webhooks/{webhookId}");
            var         parameters = new Dictionary <string, string> {
                { "groupId", groupId.Value }, { "policyId", policyId.Value }, { "webhookId", webhookId.Value }
            };

            Func <Task <Tuple <IdentityToken, Uri> >, Task <HttpWebRequest> > prepareRequest =
                PrepareRequestAsyncFunc(HttpMethod.PUT, template, parameters, configuration);

            Func <Task <HttpWebRequest>, Task <string> > requestResource =
                GetResponseAsyncFunc(cancellationToken);

            return(AuthenticateServiceAsync(cancellationToken)
                   .Then(prepareRequest)
                   .Then(requestResource));
        }
Example #2
0
        /// <summary>
        /// Update the configuration for a webhook.
        /// </summary>
        /// <param name="service">The Auto Scale service instance.</param>
        /// <param name="groupId">The ID of the scaling group. This is obtained from <see cref="ScalingGroup.Id">ScalingGroup.Id</see>.</param>
        /// <param name="policyId">The ID of the scaling policy. This is obtained from <see cref="Policy.Id">Policy.Id</see>.</param>
        /// <param name="webhookId">The ID of the webhook. This is obtained from <see cref="Webhook.Id">Webhook.Id</see>.</param>
        /// <param name="configuration">An <see cref="UpdateWebhookConfiguration"/> object containing the updated configuration for the webhook.</param>
        /// <exception cref="ArgumentNullException">If <paramref name="service"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="groupId"/> is <see langword="null"/>.
        /// <para>-or-</para>
        /// <para>If <paramref name="policyId"/> is <see langword="null"/>.</para>
        /// <para>-or-</para>
        /// <para>If <paramref name="webhookId"/> is <see langword="null"/>.</para>
        /// <para>-or-</para>
        /// <para>If <paramref name="configuration"/> is <see langword="null"/>.</para>
        /// </exception>
        /// <exception cref="WebException">If the REST request does not return successfully.</exception>
        /// <seealso href="http://docs.rackspace.com/cas/api/v1.0/autoscale-devguide/content/PUT_putWebhook_v1.0__tenantId__groups__groupId__policies__policyId__webhooks__webhookId__autoscale-webhooks.html">Update webhook (Rackspace Auto Scale Developer Guide - API v1.0)</seealso>
        public static void UpdateWebhook(this IAutoScaleService service, ScalingGroupId groupId, PolicyId policyId, WebhookId webhookId, UpdateWebhookConfiguration configuration)
        {
            if (service == null)
            {
                throw new ArgumentNullException("service");
            }

            try
            {
                service.UpdateWebhookAsync(groupId, policyId, webhookId, configuration, CancellationToken.None).Wait();
            }
            catch (AggregateException ex)
            {
                ReadOnlyCollection <Exception> innerExceptions = ex.Flatten().InnerExceptions;
                if (innerExceptions.Count == 1)
                {
                    throw innerExceptions[0];
                }

                throw;
            }
        }