Skip to content

Commit 58ea356

Browse files
committed
V14 Integrations (Semrush)
- Update PR based from previous comments
1 parent 2119987 commit 58ea356

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+441
-1558
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"id": "Umbraco.Cms.Integrations.Crm.ActiveCampaign",
3+
"name": "Umbraco CMS Integrations: CRM - ActiveCampaign",
4+
"version": "3.0.0",
5+
"extensions": [
6+
{
7+
"name": "Umbraco EntryPoint",
8+
"alias": "Umb.Hubspot.EntryPoint",
9+
"type": "entryPoint",
10+
"js": "/App_Plugins/ActiveCampaignForms/activecampaign.js"
11+
}
12+
]
13+
}

src/Umbraco.Cms.Integrations.SEO.Semrush/Api/Management/Controllers/AuthorizationController.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,8 @@
33
using Microsoft.AspNetCore.Http;
44
using Microsoft.AspNetCore.Mvc;
55
using Microsoft.Extensions.Options;
6-
using System;
7-
using System.Collections.Generic;
8-
using System.Linq;
9-
using System.Text;
10-
using System.Threading.Tasks;
116
using Umbraco.Cms.Integrations.SEO.Semrush.Configuration;
127
using Umbraco.Cms.Integrations.SEO.Semrush.Models;
13-
using Umbraco.Cms.Integrations.SEO.Semrush.Models.Dtos;
148
using Umbraco.Cms.Integrations.SEO.Semrush.Services;
159

1610
namespace Umbraco.Cms.Integrations.SEO.Semrush.Api.Management.Controllers
@@ -19,7 +13,14 @@ namespace Umbraco.Cms.Integrations.SEO.Semrush.Api.Management.Controllers
1913
[ApiExplorerSettings(GroupName = Constants.ManagementApi.SemrushGroupName)]
2014
public class AuthorizationController : SemrushControllerBase
2115
{
22-
public AuthorizationController(IOptions<SemrushSettings> options, IWebHostEnvironment webHostEnvironment, ISemrushTokenService semrushTokenService, ICacheHelper cacheHelper, TokenBuilder tokenBuilder, SemrushComposer.AuthorizationImplementationFactory authorizationImplementationFactory) : base(options, webHostEnvironment, semrushTokenService, cacheHelper, tokenBuilder, authorizationImplementationFactory)
16+
public AuthorizationController(
17+
IOptions<SemrushSettings> options,
18+
IWebHostEnvironment webHostEnvironment,
19+
ISemrushTokenService semrushTokenService,
20+
ICacheHelper cacheHelper,
21+
TokenBuilder tokenBuilder,
22+
SemrushComposer.AuthorizationImplementationFactory authorizationImplementationFactory,
23+
IHttpClientFactory httpClientFactory) : base(options, webHostEnvironment, semrushTokenService, cacheHelper, tokenBuilder, authorizationImplementationFactory, httpClientFactory)
2324
{
2425
}
2526

src/Umbraco.Cms.Integrations.SEO.Semrush/Api/Management/Controllers/GetAuthorizationUrlController.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
using Microsoft.AspNetCore.Http;
44
using Microsoft.AspNetCore.Mvc;
55
using Microsoft.Extensions.Options;
6-
using System;
7-
using System.Collections.Generic;
8-
using System.Linq;
9-
using System.Text;
10-
using System.Threading.Tasks;
116
using Umbraco.Cms.Integrations.SEO.Semrush.Configuration;
127
using Umbraco.Cms.Integrations.SEO.Semrush.Services;
138

@@ -17,11 +12,18 @@ namespace Umbraco.Cms.Integrations.SEO.Semrush.Api.Management.Controllers
1712
[ApiExplorerSettings(GroupName = Constants.ManagementApi.SemrushGroupName)]
1813
public class GetAuthorizationUrlController : SemrushControllerBase
1914
{
20-
public GetAuthorizationUrlController(IOptions<SemrushSettings> options, IWebHostEnvironment webHostEnvironment, ISemrushTokenService semrushTokenService, ICacheHelper cacheHelper, TokenBuilder tokenBuilder, SemrushComposer.AuthorizationImplementationFactory authorizationImplementationFactory) : base(options, webHostEnvironment, semrushTokenService, cacheHelper, tokenBuilder, authorizationImplementationFactory)
15+
public GetAuthorizationUrlController(
16+
IOptions<SemrushSettings> options,
17+
IWebHostEnvironment webHostEnvironment,
18+
ISemrushTokenService semrushTokenService,
19+
ICacheHelper cacheHelper,
20+
TokenBuilder tokenBuilder,
21+
SemrushComposer.AuthorizationImplementationFactory authorizationImplementationFactory,
22+
IHttpClientFactory httpClientFactory) : base(options, webHostEnvironment, semrushTokenService, cacheHelper, tokenBuilder, authorizationImplementationFactory, httpClientFactory)
2123
{
2224
}
2325

24-
[HttpGet("auth-url")]
26+
[HttpGet("auth/url")]
2527
[ProducesResponseType(typeof(string), StatusCodes.Status200OK)]
2628
public IActionResult GetAuthorizationUrl() => Ok(_authorizationService.GetAuthorizationUrl());
2729
}

src/Umbraco.Cms.Integrations.SEO.Semrush/Api/Management/Controllers/GetColumnsController.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@
33
using Microsoft.AspNetCore.Http;
44
using Microsoft.AspNetCore.Mvc;
55
using Microsoft.Extensions.Options;
6-
using System;
7-
using System.Collections.Generic;
8-
using System.Linq;
9-
using System.Text;
106
using System.Text.Json;
11-
using System.Threading.Tasks;
127
using Umbraco.Cms.Integrations.SEO.Semrush.Configuration;
138
using Umbraco.Cms.Integrations.SEO.Semrush.Models.Dtos;
149
using Umbraco.Cms.Integrations.SEO.Semrush.Services;
@@ -19,15 +14,22 @@ namespace Umbraco.Cms.Integrations.SEO.Semrush.Api.Management.Controllers
1914
[ApiExplorerSettings(GroupName = Constants.ManagementApi.SemrushGroupName)]
2015
public class GetColumnsController : SemrushControllerBase
2116
{
22-
public GetColumnsController(IOptions<SemrushSettings> options, IWebHostEnvironment webHostEnvironment, ISemrushTokenService semrushTokenService, ICacheHelper cacheHelper, TokenBuilder tokenBuilder, SemrushComposer.AuthorizationImplementationFactory authorizationImplementationFactory) : base(options, webHostEnvironment, semrushTokenService, cacheHelper, tokenBuilder, authorizationImplementationFactory)
17+
public GetColumnsController(
18+
IOptions<SemrushSettings> options,
19+
IWebHostEnvironment webHostEnvironment,
20+
ISemrushTokenService semrushTokenService,
21+
ICacheHelper cacheHelper,
22+
TokenBuilder tokenBuilder,
23+
SemrushComposer.AuthorizationImplementationFactory authorizationImplementationFactory,
24+
IHttpClientFactory httpClientFactory) : base(options, webHostEnvironment, semrushTokenService, cacheHelper, tokenBuilder, authorizationImplementationFactory, httpClientFactory)
2325
{
2426
}
2527

2628
[HttpGet("columns")]
2729
[ProducesResponseType(typeof(IEnumerable<ColumnDto>), StatusCodes.Status200OK)]
2830
public IActionResult GetColumns()
2931
{
30-
string semrushColumnsPath = $"{_webHostEnvironment.ContentRootPath}/App_Plugins/UmbracoCms.Integrations/SEO/Semrush/semrushColumns.json";
32+
string semrushColumnsPath = "semrushColumns.json";
3133

3234
_lock.EnterReadLock();
3335

src/Umbraco.Cms.Integrations.SEO.Semrush/Api/Management/Controllers/GetCurrentContentPropertiesController.cs

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,51 @@ namespace Umbraco.Cms.Integrations.SEO.Semrush.Api.Management.Controllers
1515
public class GetCurrentContentPropertiesController : SemrushControllerBase
1616
{
1717
private readonly IContentService _contentService;
18-
public GetCurrentContentPropertiesController(IOptions<SemrushSettings> options,
19-
IWebHostEnvironment webHostEnvironment,
20-
ISemrushTokenService semrushTokenService,
21-
ICacheHelper cacheHelper,
22-
TokenBuilder tokenBuilder,
18+
private readonly IContentTypeService _contentTypeService;
19+
public GetCurrentContentPropertiesController(IOptions<SemrushSettings> options,
20+
IWebHostEnvironment webHostEnvironment,
21+
ISemrushTokenService semrushTokenService,
22+
ICacheHelper cacheHelper,
23+
TokenBuilder tokenBuilder,
2324
SemrushComposer.AuthorizationImplementationFactory authorizationImplementationFactory,
24-
IContentService contentService) : base(options, webHostEnvironment, semrushTokenService, cacheHelper, tokenBuilder, authorizationImplementationFactory)
25+
IContentService contentService,
26+
IContentTypeService contentTypeService,
27+
IHttpClientFactory httpClientFactory) : base(options, webHostEnvironment, semrushTokenService, cacheHelper, tokenBuilder, authorizationImplementationFactory, httpClientFactory)
2528
{
2629
_contentService = contentService;
30+
_contentTypeService = contentTypeService;
2731
}
2832

2933
[HttpGet("content-properties")]
3034
[ProducesResponseType(typeof(List<ContentPropertyDto>), StatusCodes.Status200OK)]
3135
public async Task<IActionResult> GetCurrentContentProperties(string contentId)
3236
{
3337
var propertyList = new List<ContentPropertyDto>();
38+
var currentContent = _contentService.GetById(Guid.Parse(contentId));
39+
var propertiesInCurrentContent = currentContent.Properties.ToList();
40+
var contentTypeOfCurrentContent = _contentTypeService.Get(currentContent.ContentType.Id);
41+
var contentGroupsOfCurrentContentType = contentTypeOfCurrentContent.PropertyGroups.ToList();
3442

35-
var content = _contentService.GetById(Guid.Parse(contentId));
36-
if (content != null)
43+
for(int i = 0; i < contentGroupsOfCurrentContentType.Count; i++)
3744
{
38-
propertyList = content.Properties.Select(s => new ContentPropertyDto { PropertyName = s.PropertyType.Name, PropertyValue = s.Values.ToList()[0].PublishedValue.ToString() }).ToList();
45+
var properties = contentGroupsOfCurrentContentType[i].PropertyTypes.ToList();
46+
47+
for(int j = 0; j < properties.Count; j++)
48+
{
49+
var property = properties[j];
50+
var value = propertiesInCurrentContent.Where(p => p.PropertyTypeId == property.Id).FirstOrDefault().Values;
51+
if(value != null && value.Count > 0)
52+
{
53+
propertyList.Add(new ContentPropertyDto
54+
{
55+
PropertyName = property.Name,
56+
PropertyGroup = contentGroupsOfCurrentContentType[i].Name,
57+
PropertyValue = value.FirstOrDefault().PublishedValue.ToString()
58+
});
59+
}
60+
}
3961
}
40-
62+
4163
return Ok(propertyList);
4264
}
4365
}

src/Umbraco.Cms.Integrations.SEO.Semrush/Api/Management/Controllers/GetDataSourcesController.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@
33
using Microsoft.AspNetCore.Http;
44
using Microsoft.AspNetCore.Mvc;
55
using Microsoft.Extensions.Options;
6-
using System;
7-
using System.Collections.Generic;
8-
using System.Linq;
9-
using System.Text;
106
using System.Text.Json;
11-
using System.Threading.Tasks;
127
using Umbraco.Cms.Integrations.SEO.Semrush.Configuration;
138
using Umbraco.Cms.Integrations.SEO.Semrush.Models.Dtos;
149
using Umbraco.Cms.Integrations.SEO.Semrush.Services;
@@ -19,15 +14,20 @@ namespace Umbraco.Cms.Integrations.SEO.Semrush.Api.Management.Controllers
1914
[ApiExplorerSettings(GroupName = Constants.ManagementApi.SemrushGroupName)]
2015
public class GetDataSourcesController : SemrushControllerBase
2116
{
22-
public GetDataSourcesController(IOptions<SemrushSettings> options, IWebHostEnvironment webHostEnvironment, ISemrushTokenService semrushTokenService, ICacheHelper cacheHelper, TokenBuilder tokenBuilder, SemrushComposer.AuthorizationImplementationFactory authorizationImplementationFactory) : base(options, webHostEnvironment, semrushTokenService, cacheHelper, tokenBuilder, authorizationImplementationFactory)
17+
public GetDataSourcesController(IOptions<SemrushSettings> options,
18+
IWebHostEnvironment webHostEnvironment,
19+
ISemrushTokenService semrushTokenService,
20+
ICacheHelper cacheHelper,
21+
TokenBuilder tokenBuilder,
22+
SemrushComposer.AuthorizationImplementationFactory authorizationImplementationFactory,
23+
IHttpClientFactory httpClientFactory) : base(options, webHostEnvironment, semrushTokenService, cacheHelper, tokenBuilder, authorizationImplementationFactory, httpClientFactory)
2324
{
2425
}
2526

26-
[HttpGet("datasources")]
27+
[HttpGet("data-sources")]
2728
[ProducesResponseType(typeof(DataSourceDto), StatusCodes.Status200OK)]
2829
public IActionResult GetDataSources()
2930
{
30-
//string semrushDataSourcesPath = $"{_webHostEnvironment.ContentRootPath}/App_Plugins/UmbracoCms.Integrations/SEO/Semrush/semrushDataSources.json";
3131
string semrushDataSourcesPath = "semrushDataSources.json";
3232

3333
_lock.EnterReadLock();

src/Umbraco.Cms.Integrations.SEO.Semrush/Api/Management/Controllers/GetRelatedPhrasesController.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@
33
using Microsoft.AspNetCore.Http;
44
using Microsoft.AspNetCore.Mvc;
55
using Microsoft.Extensions.Options;
6-
using System;
7-
using System.Collections.Generic;
8-
using System.Linq;
9-
using System.Text;
106
using System.Text.Json;
11-
using System.Threading.Tasks;
12-
using Umbraco.Cms.Core.Services;
137
using Umbraco.Cms.Integrations.SEO.Semrush.Configuration;
148
using Umbraco.Cms.Integrations.SEO.Semrush.Models.Dtos;
159
using Umbraco.Cms.Integrations.SEO.Semrush.Services;
16-
using static Umbraco.Cms.Core.Constants.HttpContext;
1710

1811
namespace Umbraco.Cms.Integrations.SEO.Semrush.Api.Management.Controllers
1912
{
2013
[ApiVersion("1.0")]
2114
[ApiExplorerSettings(GroupName = Constants.ManagementApi.SemrushGroupName)]
2215
public class GetRelatedPhrasesController : SemrushControllerBase
2316
{
24-
public GetRelatedPhrasesController(IOptions<SemrushSettings> options, IWebHostEnvironment webHostEnvironment, ISemrushTokenService semrushTokenService, ICacheHelper cacheHelper, TokenBuilder tokenBuilder, SemrushComposer.AuthorizationImplementationFactory authorizationImplementationFactory) : base(options, webHostEnvironment, semrushTokenService, cacheHelper, tokenBuilder, authorizationImplementationFactory)
17+
public GetRelatedPhrasesController(
18+
IOptions<SemrushSettings> options,
19+
IWebHostEnvironment webHostEnvironment,
20+
ISemrushTokenService semrushTokenService,
21+
ICacheHelper cacheHelper,
22+
TokenBuilder tokenBuilder,
23+
SemrushComposer.AuthorizationImplementationFactory authorizationImplementationFactory,
24+
IHttpClientFactory httpClientFactory) : base(options, webHostEnvironment, semrushTokenService, cacheHelper, tokenBuilder, authorizationImplementationFactory, httpClientFactory)
2525
{
2626
}
2727

@@ -44,7 +44,8 @@ public async Task<IActionResult> GetRelatedPhrases(string phrase, int pageNumber
4444

4545
_semrushTokenService.TryGetParameters(Constants.TokenDbKey, out TokenDto token);
4646

47-
var response = await ClientFactory()
47+
var httpClient = _clientFactory.CreateClient();
48+
var response = await httpClient
4849
.GetAsync(string.Format(Constants.SemrushKeywordsEndpoint, _settings.BaseUrl, method, token.AccessToken, phrase, dataSource));
4950

5051
if (response.IsSuccessStatusCode)

src/Umbraco.Cms.Integrations.SEO.Semrush/Api/Management/Controllers/PingController.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
using Microsoft.AspNetCore.Http;
44
using Microsoft.AspNetCore.Mvc;
55
using Microsoft.Extensions.Options;
6-
using System;
7-
using System.Collections.Generic;
8-
using System.Linq;
9-
using System.Text;
10-
using System.Threading.Tasks;
116
using Umbraco.Cms.Integrations.SEO.Semrush.Configuration;
127
using Umbraco.Cms.Integrations.SEO.Semrush.Services;
138

@@ -17,7 +12,13 @@ namespace Umbraco.Cms.Integrations.SEO.Semrush.Api.Management.Controllers
1712
[ApiExplorerSettings(GroupName = Constants.ManagementApi.SemrushGroupName)]
1813
public class PingController : SemrushControllerBase
1914
{
20-
public PingController(IOptions<SemrushSettings> options, IWebHostEnvironment webHostEnvironment, ISemrushTokenService semrushTokenService, ICacheHelper cacheHelper, TokenBuilder tokenBuilder, SemrushComposer.AuthorizationImplementationFactory authorizationImplementationFactory) : base(options, webHostEnvironment, semrushTokenService, cacheHelper, tokenBuilder, authorizationImplementationFactory)
15+
public PingController(IOptions<SemrushSettings> options,
16+
IWebHostEnvironment webHostEnvironment,
17+
ISemrushTokenService semrushTokenService,
18+
ICacheHelper cacheHelper,
19+
TokenBuilder tokenBuilder,
20+
SemrushComposer.AuthorizationImplementationFactory authorizationImplementationFactory,
21+
IHttpClientFactory httpClientFactory) : base(options, webHostEnvironment, semrushTokenService, cacheHelper, tokenBuilder, authorizationImplementationFactory, httpClientFactory)
2122
{
2223
}
2324

src/Umbraco.Cms.Integrations.SEO.Semrush/Api/Management/Controllers/SemrushControllerBase.cs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
11
using Microsoft.AspNetCore.Authorization;
22
using Microsoft.AspNetCore.Hosting;
3-
using Microsoft.AspNetCore.Http;
43
using Microsoft.AspNetCore.Mvc;
54
using Microsoft.Extensions.Options;
6-
using System;
7-
using System.Collections.Generic;
8-
using System.Linq;
9-
using System.Text;
10-
using System.Threading.Tasks;
115
using Umbraco.Cms.Api.Common.Attributes;
126
using Umbraco.Cms.Integrations.SEO.Semrush.Configuration;
13-
using Umbraco.Cms.Integrations.SEO.Semrush.Models.Dtos;
147
using Umbraco.Cms.Integrations.SEO.Semrush.Services;
158
using Umbraco.Cms.Web.Common.Authorization;
169
using Umbraco.Cms.Web.Common.Routing;
@@ -24,12 +17,13 @@ namespace Umbraco.Cms.Integrations.SEO.Semrush.Api.Management.Controllers
2417
[MapToApi(Constants.ManagementApi.ApiName)]
2518
public class SemrushControllerBase : Controller
2619
{
27-
// Using a static HttpClient (see: https://www.aspnetmonsters.com/2016/08/2016-08-27-httpclientwrong/).
28-
protected readonly static HttpClient s_client = new HttpClient();
29-
30-
// Access to the client within the class is via ClientFactory(), allowing us to mock the responses in tests.
31-
protected static Func<HttpClient> ClientFactory = () => s_client;
32-
20+
protected static IHttpClientFactory _clientFactory;
21+
private IOptions<SemrushSettings> options;
22+
private IWebHostEnvironment webHostEnvironment;
23+
private ISemrushTokenService semrushTokenService;
24+
private ICacheHelper cacheHelper;
25+
private TokenBuilder tokenBuilder;
26+
private AuthorizationImplementationFactory authorizationImplementationFactory;
3327
protected static readonly ReaderWriterLockSlim _lock = new ReaderWriterLockSlim();
3428

3529
protected readonly ISemrushTokenService _semrushTokenService;
@@ -48,14 +42,16 @@ public SemrushControllerBase(IOptions<SemrushSettings> options,
4842
IWebHostEnvironment webHostEnvironment,
4943
ISemrushTokenService semrushTokenService,
5044
ICacheHelper cacheHelper, TokenBuilder tokenBuilder,
51-
AuthorizationImplementationFactory authorizationImplementationFactory)
45+
AuthorizationImplementationFactory authorizationImplementationFactory,
46+
IHttpClientFactory clientFactory)
5247
{
5348
_settings = options.Value;
5449
_webHostEnvironment = webHostEnvironment;
5550
_semrushTokenService = semrushTokenService;
5651
_cacheHelper = cacheHelper;
5752
_tokenBuilder = tokenBuilder;
5853
_authorizationService = authorizationImplementationFactory(_settings.UseUmbracoAuthorization);
54+
_clientFactory = clientFactory;
5955
}
6056
}
6157
}

0 commit comments

Comments
 (0)