Skip to content

Commit c55aab7

Browse files
authored
Merge pull request #23 from Dwarner123/master
Add Create Update Method to Contact API
2 parents 247895f + 3ed5517 commit c55aab7

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

HubSpot.NET/Api/Contact/HubSpotContactApi.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ public HubSpotContactApi(IHubSpotClient client)
3131
return _client.Execute<T>(path, entity, Method.POST);
3232
}
3333

34+
/// <summary>
35+
/// Creates or Updates a contact entity based on the Entity Email
36+
/// </summary>
37+
/// <typeparam name="T">Implementation of ContactHubSpotModel</typeparam>
38+
/// <param name="entity">The entity</param>
39+
/// <returns>The created entity (with ID set)</returns>
40+
public T CreateOrUpdate<T>(T entity) where T : ContactHubSpotModel, new()
41+
{
42+
var path = $"{entity.RouteBasePath}/contact/createOrUpdate/email/{entity.Email}/";
43+
return _client.Execute<T>(path, entity, Method.POST);
44+
}
45+
3446
/// <summary>
3547
/// Gets a single contact by ID from hubspot
3648
/// </summary>

HubSpot.NET/Api/Deal/HubSpotDealApi.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,46 @@ public HubSpotDealApi(IHubSpotClient client)
9999
return data;
100100
}
101101

102+
103+
/// <summary>
104+
/// Gets a list of deals associated to a hubSpot Object
105+
/// </summary>
106+
/// <typeparam name="T">Implementation of DealListHubSpotModel</typeparam>
107+
/// <param name="includeAssociations">Bool include associated Ids</param>
108+
/// <param name="hubId">Long Id of Hubspot object related to deals</param>
109+
/// <param name="objectName">String name of Hubspot object related to deals (contact\account)</param>
110+
/// <param name="opts">Options (limit, offset) relating to request</param>
111+
/// <returns>List of deals</returns>
112+
public DealListHubSpotModel<T> ListAssociated<T>(bool includeAssociations, long hubId, ListRequestOptions opts = null, string objectName = "contact") where T : DealHubSpotModel, new()
113+
{
114+
if (opts == null)
115+
{
116+
opts = new ListRequestOptions();
117+
}
118+
119+
var path = $"{new DealListHubSpotModel<T>().RouteBasePath}/deal/associated/{objectName}/{hubId}/paged"
120+
.SetQueryParam("limit", opts.Limit);
121+
122+
if (opts.Offset.HasValue)
123+
{
124+
path = path.SetQueryParam("offset", opts.Offset);
125+
}
126+
127+
if (includeAssociations)
128+
{
129+
path = path.SetQueryParam("includeAssociations", "true");
130+
}
131+
132+
if (opts.PropertiesToInclude.Any())
133+
{
134+
path = path.SetQueryParam("properties", opts.PropertiesToInclude);
135+
}
136+
137+
var data = _client.ExecuteList<DealListHubSpotModel<T>>(path, opts);
138+
139+
return data;
140+
}
141+
102142
/// <summary>
103143
/// Deletes a given deal (by ID)
104144
/// </summary>

HubSpot.NET/Core/Interfaces/IHubSpotContactApi.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace HubSpot.NET.Core.Interfaces
77
public interface IHubSpotContactApi
88
{
99
T Create<T>(T entity) where T : ContactHubSpotModel, new();
10+
T CreateOrUpdate<T>(T entity) where T : ContactHubSpotModel, new();
1011
void Delete(long contactId);
1112
void Batch<T>(List<T> entities) where T : ContactHubSpotModel, new();
1213
T GetByEmail<T>(string email) where T : ContactHubSpotModel, new();

HubSpot.NET/Core/Interfaces/IHubSpotDealApi.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ DealRecentListHubSpotModel<T> RecentlyCreated<T>(DealRecentRequestOptions opts =
1818

1919
DealRecentListHubSpotModel<T> RecentlyUpdated<T>(DealRecentRequestOptions opts = null)
2020
where T : DealHubSpotModel, new();
21+
DealListHubSpotModel<T> ListAssociated<T>(bool includeAssociations, long hubId, ListRequestOptions opts = null, string objectName = "contact") where T :DealHubSpotModel, new();
2122
}
2223
}

0 commit comments

Comments
 (0)