Skip to content

Commit

Permalink
Issue #8
Browse files Browse the repository at this point in the history
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
  • Loading branch information
cdmdotnet committed Feb 22, 2022
1 parent 96a88c0 commit 21be13f
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 15 deletions.
55 changes: 54 additions & 1 deletion HubSpot.NET.Examples/Companies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public static void Example(HubSpotApi api)
/**
* Search for a company
*/
string searchValue = company.Name;
SearchRequestFilterOperatorType searchOperator = SearchRequestFilterOperatorType.EqualTo;
var searchedCompany = api.Company.Search<CompanyHubSpotModel>(new SearchRequestOptions()
{
FilterGroups = new List<SearchRequestFilterGroup>
Expand All @@ -48,7 +50,8 @@ public static void Example(HubSpotApi api)
new SearchRequestFilter
{
PropertyName = "name",
Value = company.Name
Operator = searchOperator,
Value = searchValue
}
}
}
Expand Down Expand Up @@ -77,6 +80,56 @@ public static void Example(HubSpotApi api)
* Delete a contact
*/
api.Company.Delete(company.Id.Value);

/*
* Create several companies and test searching
*/
IList<CompanyHubSpotModel> sampleCompanies = new List<CompanyHubSpotModel>();
for (int i = 1; i <= 22; i++)
{
company = api.Company.Create(new CompanyHubSpotModel()
{
Domain = "squaredup.com",
Name = $"Squared Up {i:N0}"
});
sampleCompanies.Add(company);
}
searchValue = "Squared Up";
searchOperator = SearchRequestFilterOperatorType.ContainsAToken;
var searchedCompanies = api.Company.Search<CompanyHubSpotModel>(new SearchRequestOptions()
{
FilterGroups = new List<SearchRequestFilterGroup>
{
new SearchRequestFilterGroup
{
Filters = new List<SearchRequestFilter>
{
new SearchRequestFilter
{
PropertyName = "name",
Operator = searchOperator,
Value = searchValue
}
}
}
},
PropertiesToInclude = new List<string>
{
"domain", "name", "website"
}
});
if (searchedCompanies.Total < 1)
throw new InvalidOperationException("No companies found.");
if (searchedCompanies.Total != 22)
throw new InvalidOperationException($"'{searchedCompanies.Total:N0}' companies found when we expected 22.");
if (searchedCompanies.Paging == null || searchedCompanies.Paging.Next == null || string.IsNullOrWhiteSpace(searchedCompanies.Paging.Next.After))
throw new InvalidOperationException("Paging did not deserlise correctly.");
if (searchedCompanies.Paging.Next.After != "20")
throw new InvalidOperationException($"'{searchedCompanies.Paging.Next.After}' as a value for Paging.Next.After was not the expted 20.");
for (int i = 0; i < sampleCompanies.Count; i++)
{
api.Company.Delete(sampleCompanies[i].Id.Value);
}
}
}
}
2 changes: 1 addition & 1 deletion HubSpot.NET.Examples/Deals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static void Example(HubSpotApi api)
{
new SearchRequestFilter
{
Operator = "EQ",
Operator = SearchRequestFilterOperatorType.EqualTo,
PropertyName = "dealname",
Value = deal.Name
}
Expand Down
3 changes: 0 additions & 3 deletions HubSpot.NET.Examples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ public class Examples
{
static void Main(string[] args)
{
var _ = new Core.Requests.RequestSerializer(new Core.Requests.RequestDataConverter());
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}]}");

/**
* Initialize the API with your API Key
* You can find or generate this under Integrations -> HubSpot API key
Expand Down
4 changes: 2 additions & 2 deletions HubSpot.NET/Api/SearchRequestFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ public class SearchRequestFilter
public string PropertyName { get; set; }

[DataMember(Name = "operator")]
public string Operator { get; set; }
public SearchRequestFilterOperatorType Operator { get; set; }

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

public SearchRequestFilter()
{
Operator = "EQ";
Operator = SearchRequestFilterOperatorType.EqualTo;
}
}
}
37 changes: 37 additions & 0 deletions HubSpot.NET/Api/SearchRequestFilterOperatorType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System.Runtime.Serialization;

namespace HubSpot.NET.Api
{
public enum SearchRequestFilterOperatorType
{
[EnumMember(Value = "LT")]
LessThan,

[EnumMember(Value = "LTE")]
LessThanOrEqualTo,

[EnumMember(Value = "GT")]
GreaterThan,

[EnumMember(Value = "GTE")]
GreaterThanOrEqualTo,

[EnumMember(Value = "EQ")]
EqualTo,

[EnumMember(Value = "NEQ")]
NotEqualTo,

[EnumMember(Value = "HAS_PROPERTY")]
HasAValue,

[EnumMember(Value = "NOT_HAS_PROPERTY")]
DoesNotHaveAValue,

[EnumMember(Value = "CONTAINS_TOKEN")]
ContainsAToken,

[EnumMember(Value = "NOT_CONTAINS_TOKEN")]
DoesNotContainAToken
}
}
18 changes: 18 additions & 0 deletions HubSpot.NET/Core/Requests/RequestDataConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Dynamic;
using System.Linq;
using System.Reflection;
using HubSpot.NET.Api;
using HubSpot.NET.Core.Attributes;
using HubSpot.NET.Core.Extensions;
using HubSpot.NET.Core.Interfaces;
Expand Down Expand Up @@ -261,6 +262,23 @@ internal object ConvertSingleEntity(ExpandoObject dynamicObject, object dto)
isDeletedProp?.SetValue(dto, isDeletedData);
}


if (dto is PagingModel && expandoDict.TryGetValue("next", out var nextData))
{
// TODO use properly serialized name of prop to find it
var nextProp = dtoProps.SingleOrDefault(q => q.GetPropSerializedName() == "next");

var expandoEntry = nextData as ExpandoObject;
var nextDto = ConvertSingleEntity(expandoEntry, Activator.CreateInstance(nextProp.PropertyType));
nextProp?.SetValue(dto, nextDto);
}
else if (dto is NextModel && expandoDict.TryGetValue("after", out var afterData))
{
// TODO use properly serialized name of prop to find it
var afterProp = dtoProps.SingleOrDefault(q => q.GetPropSerializedName() == "after");
afterProp?.SetValue(dto, afterData);
}

// The Properties object in the json / response data contains all the props we wish to map - if that does not exist
// we cannot proceeed
if (!expandoDict.TryGetValue("properties", out var dynamicProperties)) return dto;
Expand Down
2 changes: 2 additions & 0 deletions HubSpot.NET/Core/Requests/RequestSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using HubSpot.NET.Core.Interfaces;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using Newtonsoft.Json.Converters;

namespace HubSpot.NET.Core.Requests
{
Expand All @@ -21,6 +22,7 @@ protected RequestSerializer()
_jsonSerializerSettings = new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),
Converters = new List<JsonConverter> { new StringEnumConverter() },
NullValueHandling = NullValueHandling.Ignore
};
}
Expand Down
20 changes: 12 additions & 8 deletions HubSpot.NET/HubSpot.NET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@
<PropertyGroup>
<TargetFrameworks>net46;net451;netstandard2.0</TargetFrameworks>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>0.6.19.25</Version>
<Authors>cdmdotnet Limited - originally Squared Up Ltd.</Authors>
<Company>cdmdotnet Limited - originally Squared Up Ltd.</Company>
<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>
<Copyright>2021 cdmdotnet Limited - originally Squared Up Ltd.</Copyright>
<Version>0.6.20.01</Version>
<Authors>Chinchilla Software Limited</Authors>
<Company>Chinchilla Software Limited</Company>
<Description>C# .NET Wrapper around the common HubSpot APIs.</Description>
<Copyright>2021 Chinchilla Software Limited.</Copyright>
<!--
<PackageLicenseUrl>https://github.com/Chinchilla-Software-Com/HubSpot.NET/blob/master/LICENSE</PackageLicenseUrl>
-->
<PackageLicenseUrl>https://github.com/Chinchilla-Software-Com/HubSpot.NET/blob/master/LICENSE</PackageLicenseUrl>
-->
<PackageProjectUrl>https://github.com/Chinchilla-Software-Com/HubSpot.NET</PackageProjectUrl>
<RepositoryUrl>https://github.com/Chinchilla-Software-Com/HubSpot.NET</RepositoryUrl>
<PackageTags>hubspot api wrapper c# contact company deal engagement properties crm</PackageTags>
<PackageReleaseNotes>
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 (https://github.com/Chinchilla-Software-Com/HubSpot.NET/issues/8).
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.

0.6.19.25 Patching id fields being sent when searching Hubspot deals and companies

0.6.19.22 Added HubSpot Icon to package.
Expand Down Expand Up @@ -51,7 +55,7 @@

0.6.19.1 Added ability to search for deals using v3 API with a patch for .NET Standard
</PackageReleaseNotes>
<PackageId>_SquaredUp.HubSpot.NET</PackageId>
<PackageId>Chinchilla.HubSpot.NET</PackageId>
</PropertyGroup>

<PropertyGroup>
Expand Down

0 comments on commit 21be13f

Please sign in to comment.