File tree Expand file tree Collapse file tree 2 files changed +10
-18
lines changed
src/Umbraco.Cms.Integrations.Crm.Hubspot Expand file tree Collapse file tree 2 files changed +10
-18
lines changed Original file line number Diff line number Diff line change 1
- using System . Collections . Generic ;
1
+ using System ;
2
+ using System . Collections . Generic ;
2
3
using System . Configuration ;
3
4
using System . Linq ;
5
+ using System . Net . Http ;
4
6
using System . Threading . Tasks ;
5
- using Umbraco . Cms . Integrations . Crm . Hubspot . Helpers ;
6
7
using Umbraco . Cms . Integrations . Crm . Hubspot . Models ;
7
8
using Umbraco . Cms . Integrations . Crm . Hubspot . Models . Dtos ;
8
9
using Umbraco . Web . Mvc ;
@@ -13,14 +14,17 @@ namespace Umbraco.Cms.Integrations.Crm.Hubspot.Controllers
13
14
[ PluginController ( "UmbracoCmsIntegrationsCrmHubspot" ) ]
14
15
public class FormsController : UmbracoAuthorizedApiController
15
16
{
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
+
16
23
public async Task < List < HubspotFormDto > > GetAll ( )
17
24
{
18
- //TODO: Errorhandling
19
- var httpClient = Http . GetHttpClient ( ) ;
20
-
21
25
var hubspotApiKey = ConfigurationManager . AppSettings [ "Umbraco.Cms.Integrations.Crm.Hubspot.ApiKey" ] ;
22
26
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 ) ;
24
28
var forms = await response . Content . ReadAsStringAsync ( ) ;
25
29
var hubspotForms = HubspotForms . FromJson ( forms ) ;
26
30
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments