Beispiel #1
0
        public (bool LimitReached, WebHook WebHook) Add(
            Uri payloadTargetUri,
            bool enabled,
            string[] subscribedEvents,
            SubscriptionChoice subscriptionChoice,
            string secret)
        {
            if (_webHooks.Count >= _maxCount)
            {
                // Always limit the number of webhooks. Should probably throw a custom exception too.
                return(true, null);
            }
            subscribedEvents = subscribedEvents ?? Array.Empty <string>();
            var now  = _getUtcNow();
            var item = new WebHookMemento
            {
                Id = Guid.NewGuid(),
                PayloadTargetUri   = payloadTargetUri,
                CreatedUtc         = now,
                SubscribeToEvents  = new HashSet <string>(subscribedEvents),
                SubscriptionChoice = subscriptionChoice,
                Enabled            = enabled,
                UpdatedUtc         = now,
                Secret             = secret
            };
            var webHook = new WebHook(item);

            _webHooks.Add(webHook.Id, webHook);
            return(false, webHook);
        }
Beispiel #2
0
        public (bool Exists, WebHook WebHook) Update(
            Guid webhookId,
            Uri payloadTargetUri,
            string[] subscribedEvents,
            bool enabled,
            SubscriptionChoice subscriptionChoice,
            string secret)
        {
            if (!_webHooks.ContainsKey(webhookId))
            {
                return(false, null);
            }
            var webHook = _webHooks[webhookId];

            webHook.PayloadTargetUri   = payloadTargetUri;
            webHook.SubscribeToEvents  = new HashSet <string>(subscribedEvents);
            webHook.Enabled            = enabled;
            webHook.SubscriptionChoice = subscriptionChoice;
            if (secret != null)
            {
                webHook.Secret = secret;
            }
            return(true, webHook);
        }