Skip to content

Commit

Permalink
Add webhook subscription content type and handler.
Browse files Browse the repository at this point in the history
  • Loading branch information
tusmester committed Jan 15, 2021
1 parent 609a895 commit 66b7ff3
Show file tree
Hide file tree
Showing 4 changed files with 229 additions and 0 deletions.
89 changes: 89 additions & 0 deletions src/ContentRepository/WebHooks/WebHookSubscription.cs
@@ -0,0 +1,89 @@
using SenseNet.ContentRepository;
using SenseNet.ContentRepository.Schema;
using SenseNet.ContentRepository.Storage;

// ReSharper disable InconsistentNaming
namespace SenseNet.WebHooks
{
/// <summary>
/// A Content handler that represents a webhook subscription.
/// </summary>
[ContentHandler]
public class WebHookSubscription : GenericContent
{
/// <summary>
/// Initializes a new instance of the <see cref="WebHookSubscription"/> class.
/// </summary>
/// <param name="parent">The parent.</param>
public WebHookSubscription(Node parent) : this(parent, null) { }
/// <summary>
/// Initializes a new instance of the <see cref="WebHookSubscription"/> class.
/// </summary>
/// <param name="parent">The parent.</param>
/// <param name="nodeTypeName">Name of the node type.</param>
public WebHookSubscription(Node parent, string nodeTypeName) : base(parent, nodeTypeName) { }
/// <summary>
/// Initializes a new instance of the <see cref="WebHookSubscription"/> class during the loading process.
/// Do not use this constructor directly in your code.
/// </summary>
protected WebHookSubscription(NodeToken nt) : base(nt) { }

private const string UrlPropertyName = "WebHookUrl";
[RepositoryProperty(UrlPropertyName, RepositoryDataType.String)]
public string Url
{
get => base.GetProperty<string>(UrlPropertyName);
set => base.SetProperty(UrlPropertyName, value);
}

private const string HttpMethodPropertyName = "WebHookHttpMethod";
[RepositoryProperty(HttpMethodPropertyName, RepositoryDataType.String)]
public string HttpMethod
{
get => base.GetProperty<string>(HttpMethodPropertyName);
set => base.SetProperty(HttpMethodPropertyName, value);
}

private const string EventTypePropertyName = "WebHookEventType";
[RepositoryProperty(EventTypePropertyName, RepositoryDataType.String)]
public string EventType
{
get => base.GetProperty<string>(EventTypePropertyName);
set => base.SetProperty(EventTypePropertyName, value);
}

// ===================================================================================== Overrides

/// <inheritdoc />
public override object GetProperty(string name)
{
return name switch
{
UrlPropertyName => this.Url,
HttpMethodPropertyName => this.HttpMethod,
EventTypePropertyName => this.EventType,
_ => base.GetProperty(name),
};
}

/// <inheritdoc />
public override void SetProperty(string name, object value)
{
switch (name)
{
case UrlPropertyName:
this.Url = (string)value;
break;
case HttpMethodPropertyName:
this.HttpMethod = (string)value;
break;
case EventTypePropertyName:
this.EventType = (string)value;
break;
default:
base.SetProperty(name, value);
break;
}
}
}
}
@@ -0,0 +1,83 @@
<?xml version="1.0" encoding="utf-8"?>
<Resources>
<ResourceClass name="Ctd-WebHookSubscription">
<Languages>
<Language cultureName="en">
<data name="DisplayName" xml:space="preserve">
<value>WebHook Subscription</value>
</data>
<data name="Description" xml:space="preserve">
<value>Defines an event and a 3rd party service that should be called when the event is fired.</value>
</data>
<data name="WebHookUrl-DisplayName" xml:space="preserve">
<value>Url</value>
</data>
<data name="WebHookUrl-Description" xml:space="preserve">
<value>Target url to call when the webhook is triggered.</value>
</data>
<data name="WebHookHttpMethod-DisplayName" xml:space="preserve">
<value>HTTP method</value>
</data>
<data name="WebHookHttpMethod-Description" xml:space="preserve">
<value></value>
</data>
<data name="WebHookEventType-DisplayName" xml:space="preserve">
<value>Event type</value>
</data>
<data name="WebHookEventType-Description" xml:space="preserve">
<value></value>
</data>
<data name="WebHookFilter-DisplayName" xml:space="preserve">
<value>Filter</value>
</data>
<data name="WebHookFilter-Description" xml:space="preserve">
<value></value>
</data>
<data name="WebHookHeaders-DisplayName" xml:space="preserve">
<value>HTTP headers</value>
</data>
<data name="WebHookHeaders-Description" xml:space="preserve">
<value>List of HTTP headers to add when the target service is called.</value>
</data>
</Language>
<Language cultureName="hu">
<data name="DisplayName" xml:space="preserve">
<value>WebHook felíratkozás</value>
</data>
<data name="Description" xml:space="preserve">
<value>Definiál egy eseményt, aminek hatására meghívunk egy külső szolgáltatást.</value>
</data>
<data name="WebHookUrl-DisplayName" xml:space="preserve">
<value>Url</value>
</data>
<data name="WebHookUrl-Description" xml:space="preserve">
<value>A meghívandó cél url.</value>
</data>
<data name="WebHookHttpMethod-DisplayName" xml:space="preserve">
<value>HTTP method</value>
</data>
<data name="WebHookHttpMethod-Description" xml:space="preserve">
<value></value>
</data>
<data name="WebHookEventType-DisplayName" xml:space="preserve">
<value>Esemény típusa</value>
</data>
<data name="WebHookEventType-Description" xml:space="preserve">
<value></value>
</data>
<data name="WebHookFilter-DisplayName" xml:space="preserve">
<value>Szűrő</value>
</data>
<data name="WebHookFilter-Description" xml:space="preserve">
<value></value>
</data>
<data name="WebHookHeaders-DisplayName" xml:space="preserve">
<value>HTTP fejlécek</value>
</data>
<data name="WebHookHeaders-Description" xml:space="preserve">
<value>HTTP fejlécek listája, amiket hozzá kell tenni a külső szolgáltatás meghívásakor.</value>
</data>
</Language>
</Languages>
</ResourceClass>
</Resources>
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<ContentMetaData>
<ContentType>Resource</ContentType>
<ContentName>CtdResourcesWebHookSubscription.xml</ContentName>
<Fields>
<Binary attachment="CtdResourcesWebHookSubscription.xml" />
</Fields>
<Permissions>
<Clear />
</Permissions>
</ContentMetaData>
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<ContentType name="WebHookSubscription" parentType="GenericContent" handler="SenseNet.WebHooks.WebHookSubscription" xmlns="http://schemas.sensenet.com/SenseNet/ContentRepository/ContentTypeDefinition">
<DisplayName>$Ctd-WebHookSubscription,DisplayName</DisplayName>
<Description>$Ctd-WebHookSubscription,Description</Description>
<Icon>WebHookSubscription</Icon>
<Fields>
<Field name="WebHookUrl" type="ShortText">
<DisplayName>$Ctd-WebHookSubscription,WebHookUrl-DisplayName</DisplayName>
<Description>$Ctd-WebHookSubscription,WebHookUrl-Description</Description>
<Configuration>
<Compulsory>true</Compulsory>
<DefaultValue>https://</DefaultValue>
</Configuration>
</Field>
<Field name="WebHookHttpMethod" type="Choice">
<DisplayName>$Ctd-WebHookSubscription,WebHookHttpMethod-DisplayName</DisplayName>
<Description>$Ctd-WebHookSubscription,WebHookHttpMethod-Description</Description>
<Configuration>
<AllowMultiple>false</AllowMultiple>
<AllowExtraValue>true</AllowExtraValue>
<Options>
<Option value="GET">GET</Option>
<Option value="POST" selected="true">POST</Option>
<Option value="PATCH">PATCH</Option>
<Option value="PUT">PUT</Option>
<Option value="DELETE">DELETE</Option>
</Options>
</Configuration>
</Field>
<Field name="WebHookEventType" type="ShortText">
<DisplayName>$Ctd-WebHookSubscription,WebHookEventType-DisplayName</DisplayName>
<Description>$Ctd-WebHookSubscription,WebHookEventType-Description</Description>
<Configuration>
<Compulsory>true</Compulsory>
</Configuration>
</Field>
<Field name="WebHookFilter" type="LongText">
<DisplayName>$Ctd-WebHookSubscription,WebHookFilter-DisplayName</DisplayName>
<Description>$Ctd-WebHookSubscription,WebHookFilter-Description</Description>
</Field>
<Field name="WebHookHeaders" type="LongText">
<DisplayName>$Ctd-WebHookSubscription,WebHookHeaders-DisplayName</DisplayName>
<Description>$Ctd-WebHookSubscription,WebHookHeaders-Description</Description>
</Field>
</Fields>
</ContentType>

0 comments on commit 66b7ff3

Please sign in to comment.