Skip to content

Commit ea704cc

Browse files
committed
Send content values to Zapier
1 parent 4ba2866 commit ea704cc

File tree

8 files changed

+35
-199
lines changed

8 files changed

+35
-199
lines changed

src/Umbraco.Cms.Integrations.Automation.Zapier/Components/NewContentPublishedComponent.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#if NETFRAMEWORK
22
using System;
33
using System.Collections.Generic;
4+
using System.Linq;
45
using System.Threading.Tasks;
56
using Umbraco.Cms.Integrations.Automation.Zapier.Helpers;
67
using Umbraco.Cms.Integrations.Automation.Zapier.Services;
@@ -53,9 +54,21 @@ private void ContentServiceOnPublished(IContentService sender, ContentPublishedE
5354
{
5455
if (_zapierSubscriptionHookService.TryGetByAlias(node.ContentType.Alias, out var zapContentConfigList))
5556
{
57+
var content = new Dictionary<string, string>
58+
{
59+
{Constants.Content.Id, node.Id.ToString() },
60+
{Constants.Content.Name, node.Name },
61+
{Constants.Content.PublishDate, DateTime.UtcNow.ToString("s") }
62+
};
63+
64+
foreach (var nodeProperty in node.Properties)
65+
{
66+
content.Add(nodeProperty.Alias, nodeProperty.Id == 0 || nodeProperty.Values.Count == 0 ? string.Empty : nodeProperty.GetValue().ToString());
67+
}
68+
5669
foreach (var zapContentConfig in zapContentConfigList)
5770
{
58-
var result = triggerHelper.Execute(zapContentConfig.HookUrl, node.Id.ToString(), node.Name);
71+
var result = triggerHelper.Execute(zapContentConfig.HookUrl, content);
5972

6073
if (!string.IsNullOrEmpty(result))
6174
_logger.Error<NewContentPublishedComponent>(result);

src/Umbraco.Cms.Integrations.Automation.Zapier/Components/NewContentPublishedNotification.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#if NETCOREAPP
2+
using System;
3+
using System.Collections.Generic;
24
using Microsoft.Extensions.Logging;
35

46
using Umbraco.Cms.Core.Events;
@@ -33,9 +35,16 @@ public void Handle(ContentPublishedNotification notification)
3335
{
3436
if (_zapierSubscriptionHookService.TryGetByAlias(node.ContentType.Alias, out var zapContentConfigList))
3537
{
38+
var content = new Dictionary<string, string>
39+
{
40+
{Constants.Content.Id, node.Id.ToString() },
41+
{Constants.Content.Name, node.Name },
42+
{Constants.Content.PublishDate, DateTime.UtcNow.ToString("s") }
43+
};
44+
3645
foreach (var zapContentConfig in zapContentConfigList)
3746
{
38-
var result = triggerHelper.Execute(zapContentConfig.HookUrl, node.Id.ToString(), node.Name);
47+
var result = triggerHelper.Execute(zapContentConfig.HookUrl, content);
3948

4049
if (!string.IsNullOrEmpty(result))
4150
_logger.LogError(result);

src/Umbraco.Cms.Integrations.Automation.Zapier/Components/NewFormSubmittedComponent.cs

Lines changed: 0 additions & 97 deletions
This file was deleted.

src/Umbraco.Cms.Integrations.Automation.Zapier/Constants.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,5 @@ public static class Content
3333

3434
public const string PublishDate = "publishDate";
3535
}
36-
37-
public static class Form
38-
{
39-
public const string Id = "formId";
40-
41-
public const string Name = "formName";
42-
43-
public const string SubmissionDate = "submissionDate";
44-
45-
public const string PageUrl = "pageUrl";
46-
}
4736
}
4837
}

src/Umbraco.Cms.Integrations.Automation.Zapier/Helpers/TriggerHelper.cs

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
using System;
2-
using System.Collections.Generic;
1+
using System.Collections.Generic;
32
using System.Threading.Tasks;
4-
using Umbraco.Cms.Integrations.Automation.Zapier.Models.Dtos;
3+
54
using Umbraco.Cms.Integrations.Automation.Zapier.Services;
65

76
namespace Umbraco.Cms.Integrations.Automation.Zapier.Helpers
@@ -15,31 +14,8 @@ public TriggerHelper(ZapierService zapierService)
1514
_zapierService = zapierService;
1615
}
1716

18-
public string Execute(string hookUrl, string contentId, string contentName)
19-
{
20-
var content = new Dictionary<string, string>
21-
{
22-
{Constants.Content.Id, contentId},
23-
{Constants.Content.Name, contentName},
24-
{Constants.Content.PublishDate, DateTime.UtcNow.ToString("s")}
25-
};
26-
27-
var t = Task.Run(
28-
async () => await _zapierService.TriggerAsync(hookUrl, content));
29-
30-
return t.Result;
31-
}
32-
33-
public string FormExecute(string hookUrl, string formId, string formName, string pageUrl)
17+
public string Execute(string hookUrl, Dictionary<string, string> content)
3418
{
35-
var content = new Dictionary<string, string>
36-
{
37-
{Constants.Form.Id, formId},
38-
{Constants.Form.Name, formName},
39-
{Constants.Form.SubmissionDate, DateTime.UtcNow.ToString("s")},
40-
{Constants.Form.PageUrl, pageUrl}
41-
};
42-
4319
var t = Task.Run(
4420
async () => await _zapierService.TriggerAsync(hookUrl, content));
4521

src/Umbraco.Cms.Integrations.Automation.Zapier/Services/ZapierFormService.cs

Lines changed: 8 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4-
using System.Reflection;
5-
using Umbraco.Cms.Integrations.Automation.Zapier.Helpers;
64

7-
#if NETCOREAPP
8-
#else
5+
#if NETFRAMEWORK
96
using System.Web.Mvc;
107
#endif
8+
9+
using Umbraco.Cms.Integrations.Automation.Zapier.Helpers;
1110
using Umbraco.Cms.Integrations.Automation.Zapier.Models.Dtos;
1211

1312
namespace Umbraco.Cms.Integrations.Automation.Zapier.Services
@@ -28,9 +27,6 @@ public ZapierFormService(IServiceProvider serviceProvider)
2827
private Type FormStorageType =>
2928
Type.GetType("Umbraco.Forms.Core.Data.Storage.IFormStorage, Umbraco.Forms.Core");
3029

31-
private Type RecordStorageType =>
32-
Type.GetType("Umbraco.Forms.Core.Data.Storage.IRecordStorage, Umbraco.Forms.Core");
33-
3430
public bool TryResolveFormService(out object formService)
3531
{
3632
#if NETCOREAPP
@@ -50,7 +46,11 @@ public IEnumerable<FormDto> GetAll()
5046

5147
var forms = (IEnumerable<object>) getAllFormsMethod.Invoke(formService, null);
5248

53-
return Enumerable.Empty<FormDto>();
49+
return forms.Select(p => new FormDto
50+
{
51+
Id = p.GetType().GetProperty("Id").GetValue(p, null).ToString(),
52+
Name = p.GetType().GetProperty("Name").GetValue(p, null).ToString()
53+
});
5454
}
5555
#else
5656
/// <summary>
@@ -88,49 +88,5 @@ public IEnumerable<FormDto> GetAll()
8888

8989
}
9090
#endif
91-
92-
public bool TryResolveRecordStorage(out object recordStorage)
93-
{
94-
#if NETCOREAPP
95-
recordStorage = _serviceProvider.GetService(RecordStorageType);
96-
#else
97-
recordStorage = DependencyResolver.Current.GetService(RecordStorageType);
98-
#endif
99-
100-
return recordStorage != null;
101-
}
102-
103-
public void AddEventHandler(object target, Action<object, object> handler)
104-
{
105-
var eventInfo = RecordStorageType.GetEvent("RecordInserting");
106-
107-
if (eventInfo == null && RecordStorageType.IsInterface)
108-
{
109-
eventInfo = GetAllEventsForInterface(RecordStorageType)
110-
.FirstOrDefault(x => x.Name == "RecordInserting");
111-
}
112-
113-
if (eventInfo == null)
114-
{
115-
throw new ArgumentOutOfRangeException("RecordInserting",
116-
$"Couldn't find event RecordInserting in type {RecordStorageType.FullName}");
117-
}
118-
119-
Delegate convertedHandler = ConvertDelegate(handler, eventInfo.EventHandlerType);
120-
eventInfo.AddEventHandler(target, convertedHandler);
121-
}
122-
123-
private IEnumerable<EventInfo> GetAllEventsForInterface(Type interfaceType) =>
124-
(new Type[] {interfaceType})
125-
.Concat(interfaceType.GetInterfaces())
126-
.SelectMany(i => i.GetEvents());
127-
128-
private Delegate ConvertDelegate(Delegate originalDelegate, Type targetDelegateType)
129-
{
130-
return Delegate.CreateDelegate(
131-
targetDelegateType,
132-
originalDelegate.Target,
133-
originalDelegate.Method);
134-
}
13591
}
13692
}

src/Umbraco.Cms.Integrations.Automation.Zapier/Services/ZapierSubscriptionHookService.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ public ZapierSubscriptionHookService(IScopeProvider scopeProvider, ILogger logge
4040
}
4141
#endif
4242

43-
44-
4543
public IEnumerable<ContentConfigDto> GetAll()
4644
{
4745
using (var scope = _scopeProvider.CreateScope())

src/Umbraco.Cms.Integrations.Automation.Zapier/ZapierComposer.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,17 @@ public void Compose(IUmbracoBuilder builder)
3030

3131
builder.Services.AddSingleton<ZapierSubscriptionHookService>();
3232

33-
builder.Services.AddSingleton<ZapierFormSubscriptionHookService>();
34-
3533
builder.Services.AddSingleton<ZapierService>();
3634

37-
builder.Services.AddSingleton<ZapierFormService>();
38-
3935
builder.Services.AddScoped<IUserValidationService, UserValidationService>();
4036
}
4137
#else
4238
public void Compose(Composition composition)
4339
{
4440
composition.Register<ZapierSubscriptionHookService>(Lifetime.Singleton);
4541

46-
composition.Register<ZapierFormSubscriptionHookService>(Lifetime.Singleton);
47-
4842
composition.Register<ZapierService>(Lifetime.Singleton);
4943

50-
composition.Register<ZapierFormService>(Lifetime.Singleton);
51-
5244
composition.Register<IUserValidationService, UserValidationService>(Lifetime.Scope);
5345
}
5446
#endif

0 commit comments

Comments
 (0)