示例#1
0
        public static Webhook MapToWebhook(WebhookModel model)
        {
            var webhook = new Webhook(model.Name, model.Endpoint);

            if (model.Inactive)
            {
                webhook.Deactivate();
            }
            if (!string.IsNullOrWhiteSpace(model.Token))
            {
                webhook.SetToken(model.Token);
            }
            webhook.SetDefaultRequest(model.DefaultRequest);
            foreach (var header in model.DefaultHeaders ?? new Dictionary <string, object>())
            {
                webhook.DefaultHeaders[header.Key] = header.Value;
            }
            foreach (var action in model.Actions ?? Enumerable.Empty <WebhookActionModel>())
            {
                webhook.AddAction(WebhookActionModel.MapToWebhookAction(action));
            }
            foreach (var trigger in model.Triggers ?? Enumerable.Empty <WebhookTriggerModel>())
            {
                webhook.AddTrigger(WebhookTriggerModel.MapToWebhookTrigger(trigger));
            }

            return(webhook);
        }