示例#1
0
        public void UpdateWebhook()
        {
            WebhookId webhookId = RandomWebhookId();
            TenantId  tenantId  = RandomTenantId();
            IEnumerable <EventTypeId> eventIds = ListOfDistinctEventIds();

            var webhook1 = new Webhook(webhookId, tenantId, eventIds, "postbackUrl", "secret");
            var webhook2 = new Webhook(webhookId, tenantId, eventIds, "updatedUrl", "updatedSecret");

            sut.Add(webhook1);

            sut.Update(webhook2);

            Assert.AreEqual(1, sut.GetAll(tenantId).Count());

            var result = sut.Get(webhookId, tenantId);

            result.Match
            (
                none: Assert.Fail,
                some: (value) =>
            {
                Assert.IsTrue("updatedUrl" == value.PostbackUrl);
                Assert.IsTrue("updatedSecret" == value.Secret);
            }
            );
        }
        /// <inheritdoc/>
        public Task DeleteWebhookAsync(ScalingGroupId groupId, PolicyId policyId, WebhookId webhookId, CancellationToken cancellationToken)
        {
            if (groupId == null)
            {
                throw new ArgumentNullException("groupId");
            }
            if (policyId == null)
            {
                throw new ArgumentNullException("policyId");
            }
            if (webhookId == null)
            {
                throw new ArgumentNullException("webhookId");
            }

            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> >, HttpWebRequest> prepareRequest =
                PrepareRequestAsyncFunc(HttpMethod.DELETE, template, parameters);

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

            return(AuthenticateServiceAsync(cancellationToken)
                   .Select(prepareRequest)
                   .Then(requestResource));
        }
示例#3
0
        public void NonExistingWebhook()
        {
            WebhookId webhookId = RandomWebhookId();
            TenantId  tenantId  = RandomTenantId();

            sut.Delete(webhookId, tenantId);

            Assert.Pass();
        }
示例#4
0
        public void WebhookDoesNotExist()
        {
            WebhookId webhookId = RandomWebhookId();
            TenantId  tenantId  = RandomTenantId();

            sut.Get(webhookId, tenantId).Match
            (
                none: () => Assert.Pass(),
                some: (result) => Assert.Fail()
            );
        }
        public Maybe <Webhook> Get(WebhookId webhookId, TenantId tenantId)
        {
            var all    = GetAll(tenantId);
            var result = all.Where(w => w.Id.Equals(webhookId));

            if (result.Count() == 0)
            {
                return(new Maybe <Webhook>());
            }

            return(new Maybe <Webhook>(result.First()));
        }
示例#6
0
        public void WebhookIdDoesNotExist()
        {
            WebhookId webhookId = RandomWebhookId();
            TenantId  tenantId  = RandomTenantId();
            IEnumerable <EventTypeId> eventIds = ListOfDistinctEventIds();

            sut.Add(new Webhook(webhookId, tenantId, eventIds, "postbackUrl", "secret"));

            sut.Get(RandomWebhookId(), tenantId).Match
            (
                none: () => Assert.Pass(),
                some: (result) => Assert.Fail()
            );
        }
示例#7
0
        public void ExistingTenantId()
        {
            WebhookId webhookId = RandomWebhookId();
            TenantId  tenantId  = RandomTenantId();
            IEnumerable <EventTypeId> eventIds = ListOfDistinctEventIds();

            var webhook = new Webhook(webhookId, tenantId, eventIds, "postbackUrl", "secret");

            sut.Add(webhook);

            var result = sut.GetAll(tenantId);

            Assert.AreEqual(1, result.Count());
        }
        public void AddWebhook()
        {
            WebhookId webhookId = RandomWebhookId();
            TenantId  tenantId  = RandomTenantId();
            IEnumerable <EventTypeId> eventIds = ListOfDistinctEventIds();

            var webhook = new Webhook(webhookId, tenantId, eventIds, "postbackUrl", "secret");

            sut.Add(webhook);

            sut.Get(webhookId, tenantId).Match
            (
                none: () => Assert.Fail(),
                some: (result) => Assert.AreEqual(result, webhook)
            );
        }
 public void Copy(PayPalDirectPaymentSettings settings, bool fromSettings)
 {
     if (fromSettings)
     {
         MiniMapper.Map(settings, this);
     }
     else
     {
         MiniMapper.Map(this, settings);
         settings.ApiAccountName      = ApiAccountName.TrimSafe();
         settings.ApiAccountPassword  = ApiAccountPassword.TrimSafe();
         settings.ClientId            = ClientId.TrimSafe();
         settings.ExperienceProfileId = ExperienceProfileId.TrimSafe();
         settings.Secret    = Secret.TrimSafe();
         settings.Signature = Signature.TrimSafe();
         settings.WebhookId = WebhookId.TrimSafe();
     }
 }
示例#10
0
        public void Copy(PayPalPlusPaymentSettings settings, bool fromSettings)
        {
            if (fromSettings)
            {
                MiniMapper.Map(settings, this);
            }
            else
            {
                TransactMode = TransactMode.AuthorizeAndCapture;

                MiniMapper.Map(this, settings);
                settings.ApiAccountName      = ApiAccountName.TrimSafe();
                settings.ApiAccountPassword  = ApiAccountPassword.TrimSafe();
                settings.ClientId            = ClientId.TrimSafe();
                settings.ExperienceProfileId = ExperienceProfileId.TrimSafe();
                settings.Secret    = Secret.TrimSafe();
                settings.Signature = Signature.TrimSafe();
                settings.WebhookId = WebhookId.TrimSafe();
            }
        }
示例#11
0
        public void MultipleWebhooksForTenant()
        {
            WebhookId webhookId1 = RandomWebhookId();
            WebhookId webhookId2 = RandomWebhookId();

            TenantId tenantId = RandomTenantId();

            IEnumerable <EventTypeId> eventIds1 = ListOfDistinctEventIds();
            IEnumerable <EventTypeId> eventIds2 = ListOfDistinctEventIds();

            var webhook1 = new Webhook(webhookId1, tenantId, eventIds1, "postbackUrl", "secret");
            var webhook2 = new Webhook(webhookId2, tenantId, eventIds2, "postbackUrl", "secret");

            sut.Add(webhook1);
            sut.Add(webhook2);

            var result = sut.GetAll(tenantId);

            Assert.AreEqual(2, result.Count());
            Assert.IsTrue(result.Contains(webhook1));
            Assert.IsTrue(result.Contains(webhook2));
        }
 public void Delete(WebhookId webhookId, TenantId tenantId)
 {
     var deleteSubscriptionsParams = new { WebhookId = webhookId.Value };
     var deleteSubscriptionsSql    =
         @$ "delete from Subscriptions
            where WebhookId = @{nameof(deleteSubscriptionsParams.WebhookId)}";
        /// <inheritdoc/>
        public Task <ReadOnlyCollectionPage <Webhook> > ListWebhooksAsync(ScalingGroupId groupId, PolicyId policyId, WebhookId marker, int?limit, CancellationToken cancellationToken)
        {
            if (groupId == null)
            {
                throw new ArgumentNullException("groupId");
            }
            if (policyId == null)
            {
                throw new ArgumentNullException("policyId");
            }
            if (limit <= 0)
            {
                throw new ArgumentOutOfRangeException("limit");
            }

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

            if (marker != null)
            {
                parameters.Add("marker", marker.Value);
            }
            if (limit != null)
            {
                parameters.Add("limit", limit.ToString());
            }

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

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

            Func <Task <JObject>, ReadOnlyCollectionPage <Webhook> > resultSelector =
                task =>
            {
                JObject result = task.Result;
                if (result == null)
                {
                    return(null);
                }

                JToken valuesToken = result["webhooks"];
                if (valuesToken == null)
                {
                    return(null);
                }

                JToken linksToken = result["webhooks_links"];
                Link[] links      = linksToken != null?linksToken.ToObject <Link[]>() : null;

                Webhook[] values = valuesToken.ToObject <Webhook[]>();

                WebhookId nextMarker = values.Any() && (links == null || links.Any(i => string.Equals(i.Rel, "next", StringComparison.OrdinalIgnoreCase))) ? values.Last().Id : null;
                Func <CancellationToken, Task <ReadOnlyCollectionPage <Webhook> > > getNextPageAsync = null;
                if (nextMarker != null)
                {
                    getNextPageAsync = nextCancellationToken => ListWebhooksAsync(groupId, policyId, nextMarker, limit, cancellationToken);
                }

                return(new BasicReadOnlyCollectionPage <Webhook>(values, getNextPageAsync));
            };

            return(AuthenticateServiceAsync(cancellationToken)
                   .Select(prepareRequest)
                   .Then(requestResource)
                   .Select(resultSelector));
        }
        /// <inheritdoc/>
        public Task <Webhook> GetWebhookAsync(ScalingGroupId groupId, PolicyId policyId, WebhookId webhookId, CancellationToken cancellationToken)
        {
            if (groupId == null)
            {
                throw new ArgumentNullException("groupId");
            }
            if (policyId == null)
            {
                throw new ArgumentNullException("policyId");
            }
            if (webhookId == null)
            {
                throw new ArgumentNullException("webhookId");
            }

            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> >, HttpWebRequest> prepareRequest =
                PrepareRequestAsyncFunc(HttpMethod.GET, template, parameters);

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

            Func <Task <JObject>, Webhook> resultSelector =
                task =>
            {
                JObject result = task.Result;
                if (result == null)
                {
                    return(null);
                }

                JToken valueToken = result["webhook"];
                if (valueToken == null)
                {
                    return(null);
                }

                return(valueToken.ToObject <Webhook>());
            };

            return(AuthenticateServiceAsync(cancellationToken)
                   .Select(prepareRequest)
                   .Then(requestResource)
                   .Select(resultSelector));
        }
        public static void DeleteWebhook(this IAutoScaleService service, ScalingGroupId groupId, PolicyId policyId, WebhookId webhookId)
        {
            if (service == null)
                throw new ArgumentNullException("service");

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

                throw;
            }
        }
        public static ReadOnlyCollectionPage<Webhook> ListWebhooks(this IAutoScaleService service, ScalingGroupId groupId, PolicyId policyId, WebhookId marker, int? limit)
        {
            if (service == null)
                throw new ArgumentNullException("service");

            try
            {
                return service.ListWebhooksAsync(groupId, policyId, marker, limit, CancellationToken.None).Result;
            }
            catch (AggregateException ex)
            {
                ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
                if (innerExceptions.Count == 1)
                    throw innerExceptions[0];

                throw;
            }
        }
示例#17
0
        /// <summary>
        /// Gets a collection of webhooks which trigger the execution of a particular
        /// scaling policy.
        /// </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="marker">The <see cref="Webhook.Id"/> of the last item in the previous list. Used for <see href="http://docs.rackspace.com/cas/api/v1.0/autoscale-devguide/content/pagination.html">pagination</see>. If the value is <see langword="null"/>, the list starts at the beginning.</param>
        /// <param name="limit">Indicates the maximum number of items to return. Used for <see href="http://docs.rackspace.com/cas/api/v1.0/autoscale-devguide/content/pagination.html">pagination</see>. If the value is <see langword="null"/>, a provider-specific default value is used.</param>
        /// <returns>A collection of <see cref="Webhook"/> objects describing the webhooks for the scaling policy.</returns>
        /// <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>
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">If <paramref name="limit"/> is less than or equal to 0.</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/GET_getWebhooks_v1.0__tenantId__groups__groupId__policies__policyId__webhooks_autoscale-webhooks.html">List webhooks for the policy (Rackspace Auto Scale Developer Guide - API v1.0)</seealso>
        public static ReadOnlyCollectionPage <Webhook> ListWebhooks(this IAutoScaleService service, ScalingGroupId groupId, PolicyId policyId, WebhookId marker, int?limit)
        {
            if (service == null)
            {
                throw new ArgumentNullException("service");
            }

            try
            {
                return(service.ListWebhooksAsync(groupId, policyId, marker, limit, CancellationToken.None).Result);
            }
            catch (AggregateException ex)
            {
                ReadOnlyCollection <Exception> innerExceptions = ex.Flatten().InnerExceptions;
                if (innerExceptions.Count == 1)
                {
                    throw innerExceptions[0];
                }

                throw;
            }
        }
示例#18
0
        /// <summary>
        /// Remove and delete a webhook associated with a scaling policy.
        /// </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>
        /// <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>
        /// </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/DELETE_deleteWebhook_v1.0__tenantId__groups__groupId__policies__policyId__webhooks__webhookId__autoscale-webhooks.html">Delete webhook (Rackspace Auto Scale Developer Guide - API v1.0)</seealso>
        public static void DeleteWebhook(this IAutoScaleService service, ScalingGroupId groupId, PolicyId policyId, WebhookId webhookId)
        {
            if (service == null)
            {
                throw new ArgumentNullException("service");
            }

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

                throw;
            }
        }
 public void Delete(WebhookId webhookId, TenantId tenantId)
 {
     this.WebhookSubscriptionsStore.Delete(webhookId.Value);
 }