Skip to content

Commit 43c6d46

Browse files
committed
Add content factory
1 parent d4e185e commit 43c6d46

14 files changed

+273
-166
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using Umbraco.Core.Logging;
88
using Umbraco.Core.Services;
99
using Umbraco.Core.Services.Implement;
10-
using Umbraco.Cms.Integrations.Automation.Zapier.Extensions;
1110

1211
namespace Umbraco.Cms.Integrations.Automation.Zapier.Components
1312
{
@@ -22,14 +21,22 @@ public class NewContentPublishedComponent : IComponent
2221

2322
private readonly ZapierService _zapierService;
2423

24+
private readonly IZapierContentService _zapierContentService;
25+
2526
private readonly ILogger _logger;
2627

27-
public NewContentPublishedComponent(ZapierSubscriptionHookService zapierSubscriptionHookService, ZapierService zapierService, ILogger logger)
28+
public NewContentPublishedComponent(
29+
ZapierSubscriptionHookService zapierSubscriptionHookService,
30+
ZapierService zapierService,
31+
IZapierContentService zapierContentService,
32+
ILogger logger)
2833
{
2934
_zapierSubscriptionHookService = zapierSubscriptionHookService;
3035

3136
_zapierService = zapierService;
3237

38+
_zapierContentService = zapierContentService;
39+
3340
_logger = logger;
3441
}
3542

@@ -51,7 +58,7 @@ private void ContentServiceOnPublished(IContentService sender, ContentPublishedE
5158
{
5259
if (_zapierSubscriptionHookService.TryGetByAlias(node.ContentType.Alias, out var zapContentConfigList))
5360
{
54-
var content = node.ToContentDictionary();
61+
var content = _zapierContentService.GetContentDictionary(node);
5562

5663
foreach (var zapContentConfig in zapContentConfigList)
5764
{

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using Umbraco.Cms.Core.Events;
55
using Umbraco.Cms.Core.Notifications;
6-
using Umbraco.Cms.Integrations.Automation.Zapier.Extensions;
76
using Umbraco.Cms.Integrations.Automation.Zapier.Helpers;
87
using Umbraco.Cms.Integrations.Automation.Zapier.Services;
98

@@ -15,14 +14,22 @@ public class NewContentPublishedNotification : INotificationHandler<ContentPubli
1514

1615
private readonly ZapierService _zapierService;
1716

17+
private readonly IZapierContentService _zapierContentService;
18+
1819
private readonly ILogger<NewContentPublishedNotification> _logger;
1920

20-
public NewContentPublishedNotification(ZapierSubscriptionHookService zapierSubscriptionHookService, ZapierService zapierService, ILogger<NewContentPublishedNotification> logger)
21+
public NewContentPublishedNotification(
22+
ZapierSubscriptionHookService zapierSubscriptionHookService,
23+
ZapierService zapierService,
24+
IZapierContentService zapierContentService,
25+
ILogger<NewContentPublishedNotification> logger)
2126
{
2227
_zapierSubscriptionHookService = zapierSubscriptionHookService;
2328

2429
_zapierService = zapierService;
2530

31+
_zapierContentService = zapierContentService;
32+
2633
_logger = logger;
2734
}
2835

@@ -34,7 +41,7 @@ public void Handle(ContentPublishedNotification notification)
3441
{
3542
if (_zapierSubscriptionHookService.TryGetByAlias(node.ContentType.Alias, out var zapContentConfigList))
3643
{
37-
var content = node.ToContentDictionary();
44+
var content = _zapierContentService.GetContentDictionary(node);
3845

3946
foreach (var zapContentConfig in zapContentConfigList)
4047
{

src/Umbraco.Cms.Integrations.Automation.Zapier/Controllers/PollingController.cs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System.Collections.Generic;
22
using System.Linq;
33

4-
using Umbraco.Cms.Integrations.Automation.Zapier.Extensions;
54
using Umbraco.Cms.Integrations.Automation.Zapier.Services;
65

76
#if NETCOREAPP
@@ -25,22 +24,33 @@ public class PollingController : ZapierAuthorizedApiController
2524
{
2625
private readonly IContentTypeService _contentTypeService;
2726

27+
private readonly IZapierContentService _zapierContentService;
28+
2829
#if NETCOREAPP
2930
private readonly UmbracoHelper _umbracoHelper;
3031

31-
public PollingController(IOptions<ZapierSettings> options, IContentService contentService, IContentTypeService contentTypeService, UmbracoHelper umbracoHelper,
32-
IUserValidationService userValidationService)
32+
public PollingController(
33+
IOptions<ZapierSettings> options,
34+
IContentService contentService,
35+
IContentTypeService contentTypeService,
36+
UmbracoHelper umbracoHelper,
37+
IUserValidationService userValidationService,
38+
IZapierContentService zapierContentService)
3339
: base(options, userValidationService)
3440
#else
35-
public PollingController(IContentTypeService contentTypeService, IUserValidationService userValidationService)
41+
public PollingController(
42+
IContentTypeService contentTypeService,
43+
IUserValidationService userValidationService,
44+
IZapierContentService zapierContentService)
3645
: base(userValidationService)
3746
#endif
3847
{
3948
_contentTypeService = contentTypeService;
4049

50+
_zapierContentService = zapierContentService;
51+
4152
#if NETCOREAPP
4253
_umbracoHelper = umbracoHelper;
43-
#else
4454
#endif
4555
}
4656

@@ -59,7 +69,10 @@ public List<Dictionary<string, string>> GetContentByType(string alias)
5969
.OrderByDescending(p => p.UpdateDate);
6070
#endif
6171

62-
return new List<Dictionary<string, string>> { contentType.ToContentTypeDictionary(contentItems.FirstOrDefault()) };
72+
return new List<Dictionary<string, string>>
73+
{
74+
_zapierContentService.GetContentTypeDictionary(contentType, contentItems.FirstOrDefault())
75+
};
6376
}
6477

6578

src/Umbraco.Cms.Integrations.Automation.Zapier/Extensions/ContentExtensions.cs

Lines changed: 0 additions & 153 deletions
This file was deleted.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#if NETCOREAPP
2+
using Umbraco.Cms.Core.Models.PublishedContent;
3+
#else
4+
using Umbraco.Core.Models.PublishedContent;
5+
#endif
6+
7+
namespace Umbraco.Cms.Integrations.Automation.Zapier.Services
8+
{
9+
public interface IZapierContentFactory
10+
{
11+
IZapierContentParser Create(string editorAlias);
12+
}
13+
14+
public interface IZapierContentParser
15+
{
16+
string GetValue(IPublishedProperty contentProperty);
17+
}
18+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System.Collections.Generic;
2+
3+
#if NETCOREAPP
4+
using Umbraco.Cms.Core.Models;
5+
using Umbraco.Cms.Core.Models.PublishedContent;
6+
#else
7+
using Umbraco.Core.Models.PublishedContent;
8+
using Umbraco.Core.Models;
9+
10+
#endif
11+
12+
namespace Umbraco.Cms.Integrations.Automation.Zapier.Services
13+
{
14+
public interface IZapierContentService
15+
{
16+
Dictionary<string, string> GetContentTypeDictionary(IContentType contentType, IPublishedContent content);
17+
18+
Dictionary<string, string> GetContentDictionary(IContent contentNode);
19+
}
20+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#if NETCOREAPP
2+
using Umbraco.Cms.Core.Models.PublishedContent;
3+
#else
4+
using Umbraco.Core.Models.PublishedContent;
5+
#endif
6+
7+
namespace Umbraco.Cms.Integrations.Automation.Zapier.Services.Parsers
8+
{
9+
public class DefaultParser : IZapierContentParser
10+
{
11+
public string GetValue(IPublishedProperty contentProperty) =>
12+
contentProperty.GetValue()?.ToString();
13+
}
14+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
#if NETCOREAPP
5+
using Umbraco.Cms.Core.Models.PublishedContent;
6+
#else
7+
using Umbraco.Core.Models.PublishedContent;
8+
#endif
9+
10+
namespace Umbraco.Cms.Integrations.Automation.Zapier.Services.Parsers
11+
{
12+
public class ItemsListParser : IZapierContentParser
13+
{
14+
public string GetValue(IPublishedProperty contentProperty)
15+
{
16+
var value = string.Empty;
17+
18+
var values = contentProperty.GetValue() as IEnumerable<string>;
19+
20+
return values != null
21+
? string.Join(", ", values)
22+
: contentProperty.GetValue().ToString();
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)