Skip to content

Commit da7f7e4

Browse files
authored
Merge pull request #17 from bfutrell70/recent_deals
Recent deals
2 parents efa3d08 + 4e2297c commit da7f7e4

File tree

6 files changed

+159
-1
lines changed

6 files changed

+159
-1
lines changed

HubSpot.NET.Examples/Deals.cs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using HubSpot.NET.Api.Deal.Dto;
22
using HubSpot.NET.Core;
3+
using System;
34
using System.Collections.Generic;
45

56
namespace HubSpot.NET.Examples
@@ -36,6 +37,7 @@ public static void Example()
3637

3738
/**
3839
* Get all deals
40+
* This is commented in case the HubSpot data has a large quantity of deals.
3941
*/
4042
//var moreResults = true;
4143
//long offset = 0;
@@ -46,8 +48,34 @@ public static void Example()
4648

4749
// moreResults = allDeals.MoreResultsAvailable;
4850
// if (moreResults) offset = allDeals.ContinuationOffset;
49-
5051
//}
52+
53+
/**
54+
* Get recently created deals since 7 days ago, limited to 10 records
55+
* Will default to 30 day if Since is not set.
56+
* Using DealRecentListHubSpotModel to accomodate deals returning in the "results" property.
57+
*/
58+
var currentdatetime = DateTime.SpecifyKind(DateTime.Now.AddDays(-7), DateTimeKind.Utc);
59+
var since = ((DateTimeOffset)currentdatetime).ToUnixTimeMilliseconds().ToString();
60+
61+
var recentlyCreatedDeals = api.Deal.RecentlyCreated<DealHubSpotModel>(new DealRecentRequestOptions
62+
{
63+
Limit = 10,
64+
IncludePropertyVersion = false,
65+
Since = since
66+
});
67+
68+
/**
69+
* Get recently created deals since 7 days ago, limited to 10 records
70+
* Will default to 30 day if Since is not set.
71+
* Using DealRecentListHubSpotModel to accomodate deals returning in the "results" property.
72+
*/
73+
var recentlyUpdatedDeals = api.Deal.RecentlyCreated<DealHubSpotModel>(new DealRecentRequestOptions
74+
{
75+
Limit = 10,
76+
IncludePropertyVersion = false,
77+
Since = since
78+
});
5179
}
5280
}
5381
}

HubSpot.NET/Api/Company/HubSpotCompanyApi.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,5 +119,6 @@ public void Delete(long companyId)
119119

120120
_client.Execute(path, method: Method.DELETE);
121121
}
122+
122123
}
123124
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System.Collections.Generic;
2+
using System.Runtime.Serialization;
3+
4+
namespace HubSpot.NET.Api.Deal.Dto
5+
{
6+
/// <summary>
7+
/// Models a set of results returned when querying for sets of recently created or modified deals
8+
/// </summary>
9+
/// <remarks>
10+
/// The sole reason for this class is because HubSpot uses a different property when returning
11+
/// recently created or modified deals versus all deals.
12+
///
13+
/// With retrieving all deals the deals are returned in the property "deals".
14+
/// With recent deals the deals are returned in the property "results".
15+
/// </remarks>
16+
public class DealRecentListHubSpotModel<T> : DealListHubSpotModel<T> where T : DealHubSpotModel, new()
17+
{
18+
/// <summary>
19+
/// Gets or sets the deals.
20+
/// </summary>
21+
/// <value>
22+
/// The list of deals.
23+
/// </value>
24+
[DataMember(Name = "results")]
25+
public new IList<T> Deals { get; set; } = new List<T>();
26+
27+
}
28+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using HubSpot.NET.Core;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace HubSpot.NET.Api.Deal.Dto
9+
{
10+
public class DealRecentRequestOptions : ListRequestOptions
11+
{
12+
/// <summary>
13+
/// Used to specify the oldest timestamp to use to retrieve deals
14+
/// </summary>
15+
public string Since { get; set; }
16+
17+
/// <summary>
18+
/// Specififes if the current value for a property should be fetched or all historical values
19+
/// </summary>
20+
public bool IncludePropertyVersion { get; set; } = false;
21+
}
22+
}

HubSpot.NET/Api/Deal/HubSpotDealApi.cs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,5 +109,78 @@ public void Delete(long dealId)
109109

110110
_client.Execute(path, method: Method.DELETE);
111111
}
112+
113+
/// <summary>
114+
/// Gets a list of recently created deals
115+
/// </summary>
116+
/// <typeparam name="T">Implementation of DealListHubSpotModel</typeparam>
117+
/// <param name="opts">Options (limit, offset) relating to request</param>
118+
/// <returns>List of deals</returns>
119+
public DealRecentListHubSpotModel<T> RecentlyCreated<T>(DealRecentRequestOptions opts = null) where T : DealHubSpotModel, new()
120+
{
121+
122+
if (opts == null)
123+
{
124+
opts = new DealRecentRequestOptions();
125+
}
126+
127+
var path = $"{new DealRecentListHubSpotModel<T>().RouteBasePath}/deal/recent/created"
128+
.SetQueryParam("limit", opts.Limit);
129+
130+
if (opts.Offset.HasValue)
131+
{
132+
path = path.SetQueryParam("offset", opts.Offset);
133+
}
134+
135+
if (opts.IncludePropertyVersion)
136+
{
137+
path = path.SetQueryParam("includePropertyVersions", "true");
138+
}
139+
140+
if (!string.IsNullOrEmpty(opts.Since))
141+
{
142+
path = path.SetQueryParam("since", opts.Since);
143+
}
144+
145+
var data = _client.ExecuteList<DealRecentListHubSpotModel<T>>(path, opts);
146+
147+
return data;
148+
}
149+
150+
/// <summary>
151+
/// Gets a list of recently modified deals
152+
/// </summary>
153+
/// <typeparam name="T">Implementation of DealListHubSpotModel</typeparam>
154+
/// <param name="opts">Options (limit, offset) relating to request</param>
155+
/// <returns>List of deals</returns>
156+
public DealRecentListHubSpotModel<T> RecentlyUpdated<T>(DealRecentRequestOptions opts = null) where T : DealHubSpotModel, new()
157+
{
158+
if (opts == null)
159+
{
160+
opts = new DealRecentRequestOptions();
161+
}
162+
163+
var path = $"{new DealRecentListHubSpotModel<T>().RouteBasePath}/deal/recent/modified"
164+
.SetQueryParam("limit", opts.Limit);
165+
166+
if (opts.Offset.HasValue)
167+
{
168+
path = path.SetQueryParam("offset", opts.Offset);
169+
}
170+
171+
if (opts.IncludePropertyVersion)
172+
{
173+
path = path.SetQueryParam("includePropertyVersions", "true");
174+
}
175+
176+
if (!string.IsNullOrEmpty(opts.Since))
177+
{
178+
path = path.SetQueryParam("since", opts.Since);
179+
}
180+
181+
var data = _client.ExecuteList<DealRecentListHubSpotModel<T>>(path, opts);
182+
183+
return data;
184+
}
112185
}
113186
}

HubSpot.NET/Core/Interfaces/IHubSpotDealApi.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,11 @@ public interface IHubSpotDealApi
1212

1313
DealListHubSpotModel<T> List<T>(bool includeAssociations, ListRequestOptions opts = null)
1414
where T : DealHubSpotModel, new();
15+
16+
DealRecentListHubSpotModel<T> RecentlyCreated<T>(DealRecentRequestOptions opts = null)
17+
where T : DealHubSpotModel, new();
18+
19+
DealRecentListHubSpotModel<T> RecentlyUpdated<T>(DealRecentRequestOptions opts = null)
20+
where T : DealHubSpotModel, new();
1521
}
1622
}

0 commit comments

Comments
 (0)