Skip to content

Commit 21be13f

Browse files
committed
Issue #8
0.6.20.1 Minor breaking change. The search operator string has been replaced with an enum. Patched Paging model not being properly deserialised when searching - Thanks to https://github.com/hakimio for spotting this as issue 8 (#8). With upstream development ceasing, attribution from here is now to Chinchilla Software who is maintain this fork. NuGet package names are also shifted from SquaredUp to Chinchilla
1 parent 96a88c0 commit 21be13f

8 files changed

Lines changed: 126 additions & 15 deletions

File tree

HubSpot.NET.Examples/Companies.cs

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public static void Example(HubSpotApi api)
3737
/**
3838
* Search for a company
3939
*/
40+
string searchValue = company.Name;
41+
SearchRequestFilterOperatorType searchOperator = SearchRequestFilterOperatorType.EqualTo;
4042
var searchedCompany = api.Company.Search<CompanyHubSpotModel>(new SearchRequestOptions()
4143
{
4244
FilterGroups = new List<SearchRequestFilterGroup>
@@ -48,7 +50,8 @@ public static void Example(HubSpotApi api)
4850
new SearchRequestFilter
4951
{
5052
PropertyName = "name",
51-
Value = company.Name
53+
Operator = searchOperator,
54+
Value = searchValue
5255
}
5356
}
5457
}
@@ -77,6 +80,56 @@ public static void Example(HubSpotApi api)
7780
* Delete a contact
7881
*/
7982
api.Company.Delete(company.Id.Value);
83+
84+
/*
85+
* Create several companies and test searching
86+
*/
87+
IList<CompanyHubSpotModel> sampleCompanies = new List<CompanyHubSpotModel>();
88+
for (int i = 1; i <= 22; i++)
89+
{
90+
company = api.Company.Create(new CompanyHubSpotModel()
91+
{
92+
Domain = "squaredup.com",
93+
Name = $"Squared Up {i:N0}"
94+
});
95+
sampleCompanies.Add(company);
96+
}
97+
searchValue = "Squared Up";
98+
searchOperator = SearchRequestFilterOperatorType.ContainsAToken;
99+
var searchedCompanies = api.Company.Search<CompanyHubSpotModel>(new SearchRequestOptions()
100+
{
101+
FilterGroups = new List<SearchRequestFilterGroup>
102+
{
103+
new SearchRequestFilterGroup
104+
{
105+
Filters = new List<SearchRequestFilter>
106+
{
107+
new SearchRequestFilter
108+
{
109+
PropertyName = "name",
110+
Operator = searchOperator,
111+
Value = searchValue
112+
}
113+
}
114+
}
115+
},
116+
PropertiesToInclude = new List<string>
117+
{
118+
"domain", "name", "website"
119+
}
120+
});
121+
if (searchedCompanies.Total < 1)
122+
throw new InvalidOperationException("No companies found.");
123+
if (searchedCompanies.Total != 22)
124+
throw new InvalidOperationException($"'{searchedCompanies.Total:N0}' companies found when we expected 22.");
125+
if (searchedCompanies.Paging == null || searchedCompanies.Paging.Next == null || string.IsNullOrWhiteSpace(searchedCompanies.Paging.Next.After))
126+
throw new InvalidOperationException("Paging did not deserlise correctly.");
127+
if (searchedCompanies.Paging.Next.After != "20")
128+
throw new InvalidOperationException($"'{searchedCompanies.Paging.Next.After}' as a value for Paging.Next.After was not the expted 20.");
129+
for (int i = 0; i < sampleCompanies.Count; i++)
130+
{
131+
api.Company.Delete(sampleCompanies[i].Id.Value);
132+
}
80133
}
81134
}
82135
}

HubSpot.NET.Examples/Deals.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static void Example(HubSpotApi api)
4242
{
4343
new SearchRequestFilter
4444
{
45-
Operator = "EQ",
45+
Operator = SearchRequestFilterOperatorType.EqualTo,
4646
PropertyName = "dealname",
4747
Value = deal.Name
4848
}

HubSpot.NET.Examples/Program.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ public class Examples
66
{
77
static void Main(string[] args)
88
{
9-
var _ = new Core.Requests.RequestSerializer(new Core.Requests.RequestDataConverter());
10-
var x = _.DeserializeListEntity<Api.SearchHubSpotModel<Api.Deal.Dto.DealHubSpotModel>>("{\"total\":1,\"results\":[{\"id\":\"7684897854\",\"properties\":{\"amount\":\"10\",\"closedate\":null,\"companyid\":\"3486b5ea9701412bb9a42f1850051d3e\",\"createdate\":\"2022-01-24T17:42:39.871Z\",\"date_of_last_activity\":\"2022-01-24\",\"dealId\":null,\"dealname\":\"Katlego Cathy Makiwa\",\"dealstage\":\"16575788\",\"dealtype\":\"newbusiness\",\"hs_lastmodifieddate\":\"2022-01-25T00:46:27.550Z\",\"hs_object_id\":\"7684897854\",\"id\":null,\"pipeline\":\"default\"},\"createdAt\":\"2022-01-24T17:42:39.871Z\",\"updatedAt\":\"2022-01-25T00:46:27.550Z\",\"archived\":false}]}");
11-
129
/**
1310
* Initialize the API with your API Key
1411
* You can find or generate this under Integrations -> HubSpot API key

HubSpot.NET/Api/SearchRequestFilter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ public class SearchRequestFilter
99
public string PropertyName { get; set; }
1010

1111
[DataMember(Name = "operator")]
12-
public string Operator { get; set; }
12+
public SearchRequestFilterOperatorType Operator { get; set; }
1313

1414
[DataMember(Name = "value")]
1515
public string Value { get; set; }
1616

1717
public SearchRequestFilter()
1818
{
19-
Operator = "EQ";
19+
Operator = SearchRequestFilterOperatorType.EqualTo;
2020
}
2121
}
2222
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System.Runtime.Serialization;
2+
3+
namespace HubSpot.NET.Api
4+
{
5+
public enum SearchRequestFilterOperatorType
6+
{
7+
[EnumMember(Value = "LT")]
8+
LessThan,
9+
10+
[EnumMember(Value = "LTE")]
11+
LessThanOrEqualTo,
12+
13+
[EnumMember(Value = "GT")]
14+
GreaterThan,
15+
16+
[EnumMember(Value = "GTE")]
17+
GreaterThanOrEqualTo,
18+
19+
[EnumMember(Value = "EQ")]
20+
EqualTo,
21+
22+
[EnumMember(Value = "NEQ")]
23+
NotEqualTo,
24+
25+
[EnumMember(Value = "HAS_PROPERTY")]
26+
HasAValue,
27+
28+
[EnumMember(Value = "NOT_HAS_PROPERTY")]
29+
DoesNotHaveAValue,
30+
31+
[EnumMember(Value = "CONTAINS_TOKEN")]
32+
ContainsAToken,
33+
34+
[EnumMember(Value = "NOT_CONTAINS_TOKEN")]
35+
DoesNotContainAToken
36+
}
37+
}

HubSpot.NET/Core/Requests/RequestDataConverter.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Dynamic;
44
using System.Linq;
55
using System.Reflection;
6+
using HubSpot.NET.Api;
67
using HubSpot.NET.Core.Attributes;
78
using HubSpot.NET.Core.Extensions;
89
using HubSpot.NET.Core.Interfaces;
@@ -261,6 +262,23 @@ internal object ConvertSingleEntity(ExpandoObject dynamicObject, object dto)
261262
isDeletedProp?.SetValue(dto, isDeletedData);
262263
}
263264

265+
266+
if (dto is PagingModel && expandoDict.TryGetValue("next", out var nextData))
267+
{
268+
// TODO use properly serialized name of prop to find it
269+
var nextProp = dtoProps.SingleOrDefault(q => q.GetPropSerializedName() == "next");
270+
271+
var expandoEntry = nextData as ExpandoObject;
272+
var nextDto = ConvertSingleEntity(expandoEntry, Activator.CreateInstance(nextProp.PropertyType));
273+
nextProp?.SetValue(dto, nextDto);
274+
}
275+
else if (dto is NextModel && expandoDict.TryGetValue("after", out var afterData))
276+
{
277+
// TODO use properly serialized name of prop to find it
278+
var afterProp = dtoProps.SingleOrDefault(q => q.GetPropSerializedName() == "after");
279+
afterProp?.SetValue(dto, afterData);
280+
}
281+
264282
// The Properties object in the json / response data contains all the props we wish to map - if that does not exist
265283
// we cannot proceeed
266284
if (!expandoDict.TryGetValue("properties", out var dynamicProperties)) return dto;

HubSpot.NET/Core/Requests/RequestSerializer.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using HubSpot.NET.Core.Interfaces;
66
using Newtonsoft.Json;
77
using Newtonsoft.Json.Serialization;
8+
using Newtonsoft.Json.Converters;
89

910
namespace HubSpot.NET.Core.Requests
1011
{
@@ -21,6 +22,7 @@ protected RequestSerializer()
2122
_jsonSerializerSettings = new JsonSerializerSettings
2223
{
2324
ContractResolver = new CamelCasePropertyNamesContractResolver(),
25+
Converters = new List<JsonConverter> { new StringEnumConverter() },
2426
NullValueHandling = NullValueHandling.Ignore
2527
};
2628
}

HubSpot.NET/HubSpot.NET.csproj

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,22 @@
33
<PropertyGroup>
44
<TargetFrameworks>net46;net451;netstandard2.0</TargetFrameworks>
55
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
6-
<Version>0.6.19.25</Version>
7-
<Authors>cdmdotnet Limited - originally Squared Up Ltd.</Authors>
8-
<Company>cdmdotnet Limited - originally Squared Up Ltd.</Company>
9-
<Description>C# .NET Wrapper around the common HubSpot APIs. This is a fork/continuation of the original project that now appears not to be maintained.</Description>
10-
<Copyright>2021 cdmdotnet Limited - originally Squared Up Ltd.</Copyright>
6+
<Version>0.6.20.01</Version>
7+
<Authors>Chinchilla Software Limited</Authors>
8+
<Company>Chinchilla Software Limited</Company>
9+
<Description>C# .NET Wrapper around the common HubSpot APIs.</Description>
10+
<Copyright>2021 Chinchilla Software Limited.</Copyright>
1111
<!--
12-
<PackageLicenseUrl>https://github.com/Chinchilla-Software-Com/HubSpot.NET/blob/master/LICENSE</PackageLicenseUrl>
13-
-->
12+
<PackageLicenseUrl>https://github.com/Chinchilla-Software-Com/HubSpot.NET/blob/master/LICENSE</PackageLicenseUrl>
13+
-->
1414
<PackageProjectUrl>https://github.com/Chinchilla-Software-Com/HubSpot.NET</PackageProjectUrl>
1515
<RepositoryUrl>https://github.com/Chinchilla-Software-Com/HubSpot.NET</RepositoryUrl>
1616
<PackageTags>hubspot api wrapper c# contact company deal engagement properties crm</PackageTags>
1717
<PackageReleaseNotes>
18+
0.6.20.1 Minor breaking change. The search operator string has been replaced with an enum.
19+
Patched Paging model not being properly deserialised when searching - Thanks to https://github.com/hakimio for spotting this as issue 8 (https://github.com/Chinchilla-Software-Com/HubSpot.NET/issues/8).
20+
Merged PR #7 (https://github.com/Chinchilla-Software-Com/HubSpot.NET/pull/7) to patch some bugs in Feature/email subscriptions - Thanks to https://github.com/lakesol for spotting these and contributing.
21+
1822
0.6.19.25 Patching id fields being sent when searching Hubspot deals and companies
1923

2024
0.6.19.22 Added HubSpot Icon to package.
@@ -51,7 +55,7 @@
5155

5256
0.6.19.1 Added ability to search for deals using v3 API with a patch for .NET Standard
5357
</PackageReleaseNotes>
54-
<PackageId>_SquaredUp.HubSpot.NET</PackageId>
58+
<PackageId>Chinchilla.HubSpot.NET</PackageId>
5559
</PropertyGroup>
5660

5761
<PropertyGroup>

0 commit comments

Comments
 (0)