Skip to content

Commit 5130b12

Browse files
committed
Aligned use of HttpClient with other integrations.
1 parent 6e37d8a commit 5130b12

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed

src/Umbraco.Cms.Integrations.Crm.Hubspot/Controllers/FormsController.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23
using System.Configuration;
34
using System.Linq;
5+
using System.Net.Http;
46
using System.Threading.Tasks;
5-
using Umbraco.Cms.Integrations.Crm.Hubspot.Helpers;
67
using Umbraco.Cms.Integrations.Crm.Hubspot.Models;
78
using Umbraco.Cms.Integrations.Crm.Hubspot.Models.Dtos;
89
using Umbraco.Web.Mvc;
@@ -13,14 +14,17 @@ namespace Umbraco.Cms.Integrations.Crm.Hubspot.Controllers
1314
[PluginController("UmbracoCmsIntegrationsCrmHubspot")]
1415
public class FormsController : UmbracoAuthorizedApiController
1516
{
17+
// Using a static HttpClient (see: https://www.aspnetmonsters.com/2016/08/2016-08-27-httpclientwrong/).
18+
private readonly static HttpClient s_client = new HttpClient();
19+
20+
// Access to the client within the class is via ClientFactory(), allowing us to mock the responses in tests.
21+
internal static Func<HttpClient> ClientFactory = () => s_client;
22+
1623
public async Task<List<HubspotFormDto>> GetAll()
1724
{
18-
//TODO: Errorhandling
19-
var httpClient = Http.GetHttpClient();
20-
2125
var hubspotApiKey = ConfigurationManager.AppSettings["Umbraco.Cms.Integrations.Crm.Hubspot.ApiKey"];
2226

23-
var response = await httpClient.GetAsync("https://api.hubapi.com/forms/v2/forms?hapikey=" + hubspotApiKey);
27+
var response = await ClientFactory().GetAsync("https://api.hubapi.com/forms/v2/forms?hapikey=" + hubspotApiKey);
2428
var forms = await response.Content.ReadAsStringAsync();
2529
var hubspotForms = HubspotForms.FromJson(forms);
2630

src/Umbraco.Cms.Integrations.Crm.Hubspot/Helpers/HttpClient.cs

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

0 commit comments

Comments
 (0)