diff --git a/HubSpot.NET.Examples/Deals.cs b/HubSpot.NET.Examples/Deals.cs index ff938084..965b0449 100644 --- a/HubSpot.NET.Examples/Deals.cs +++ b/HubSpot.NET.Examples/Deals.cs @@ -1,5 +1,6 @@ using HubSpot.NET.Api.Deal.Dto; using HubSpot.NET.Core; +using System; using System.Collections.Generic; namespace HubSpot.NET.Examples @@ -36,6 +37,7 @@ public static void Example() /** * Get all deals + * This is commented in case the HubSpot data has a large quantity of deals. */ //var moreResults = true; //long offset = 0; @@ -46,8 +48,34 @@ public static void Example() // moreResults = allDeals.MoreResultsAvailable; // if (moreResults) offset = allDeals.ContinuationOffset; - //} + + /** + * Get recently created deals since 7 days ago, limited to 10 records + * Will default to 30 day if Since is not set. + * Using DealRecentListHubSpotModel to accomodate deals returning in the "results" property. + */ + var currentdatetime = DateTime.SpecifyKind(DateTime.Now.AddDays(-7), DateTimeKind.Utc); + var since = ((DateTimeOffset)currentdatetime).ToUnixTimeMilliseconds().ToString(); + + var recentlyCreatedDeals = api.Deal.RecentlyCreated(new DealRecentRequestOptions + { + Limit = 10, + IncludePropertyVersion = false, + Since = since + }); + + /** + * Get recently created deals since 7 days ago, limited to 10 records + * Will default to 30 day if Since is not set. + * Using DealRecentListHubSpotModel to accomodate deals returning in the "results" property. + */ + var recentlyUpdatedDeals = api.Deal.RecentlyCreated(new DealRecentRequestOptions + { + Limit = 10, + IncludePropertyVersion = false, + Since = since + }); } } } diff --git a/HubSpot.NET/Api/Company/HubSpotCompanyApi.cs b/HubSpot.NET/Api/Company/HubSpotCompanyApi.cs index 9b13573f..65cb0787 100644 --- a/HubSpot.NET/Api/Company/HubSpotCompanyApi.cs +++ b/HubSpot.NET/Api/Company/HubSpotCompanyApi.cs @@ -119,5 +119,6 @@ public void Delete(long companyId) _client.Execute(path, method: Method.DELETE); } + } } \ No newline at end of file diff --git a/HubSpot.NET/Api/Deal/Dto/DealRecentListHubSpotModel.cs b/HubSpot.NET/Api/Deal/Dto/DealRecentListHubSpotModel.cs new file mode 100644 index 00000000..cf6ce795 --- /dev/null +++ b/HubSpot.NET/Api/Deal/Dto/DealRecentListHubSpotModel.cs @@ -0,0 +1,28 @@ +using System.Collections.Generic; +using System.Runtime.Serialization; + +namespace HubSpot.NET.Api.Deal.Dto +{ + /// + /// Models a set of results returned when querying for sets of recently created or modified deals + /// + /// + /// The sole reason for this class is because HubSpot uses a different property when returning + /// recently created or modified deals versus all deals. + /// + /// With retrieving all deals the deals are returned in the property "deals". + /// With recent deals the deals are returned in the property "results". + /// + public class DealRecentListHubSpotModel : DealListHubSpotModel where T : DealHubSpotModel, new() + { + /// + /// Gets or sets the deals. + /// + /// + /// The list of deals. + /// + [DataMember(Name = "results")] + public new IList Deals { get; set; } = new List(); + + } +} diff --git a/HubSpot.NET/Api/Deal/Dto/DealRecentRequestOptions.cs b/HubSpot.NET/Api/Deal/Dto/DealRecentRequestOptions.cs new file mode 100644 index 00000000..b928945a --- /dev/null +++ b/HubSpot.NET/Api/Deal/Dto/DealRecentRequestOptions.cs @@ -0,0 +1,22 @@ +using HubSpot.NET.Core; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HubSpot.NET.Api.Deal.Dto +{ + public class DealRecentRequestOptions : ListRequestOptions + { + /// + /// Used to specify the oldest timestamp to use to retrieve deals + /// + public string Since { get; set; } + + /// + /// Specififes if the current value for a property should be fetched or all historical values + /// + public bool IncludePropertyVersion { get; set; } = false; + } +} diff --git a/HubSpot.NET/Api/Deal/HubSpotDealApi.cs b/HubSpot.NET/Api/Deal/HubSpotDealApi.cs index 39e45928..968a22ea 100644 --- a/HubSpot.NET/Api/Deal/HubSpotDealApi.cs +++ b/HubSpot.NET/Api/Deal/HubSpotDealApi.cs @@ -109,5 +109,78 @@ public void Delete(long dealId) _client.Execute(path, method: Method.DELETE); } + + /// + /// Gets a list of recently created deals + /// + /// Implementation of DealListHubSpotModel + /// Options (limit, offset) relating to request + /// List of deals + public DealRecentListHubSpotModel RecentlyCreated(DealRecentRequestOptions opts = null) where T : DealHubSpotModel, new() + { + + if (opts == null) + { + opts = new DealRecentRequestOptions(); + } + + var path = $"{new DealRecentListHubSpotModel().RouteBasePath}/deal/recent/created" + .SetQueryParam("limit", opts.Limit); + + if (opts.Offset.HasValue) + { + path = path.SetQueryParam("offset", opts.Offset); + } + + if (opts.IncludePropertyVersion) + { + path = path.SetQueryParam("includePropertyVersions", "true"); + } + + if (!string.IsNullOrEmpty(opts.Since)) + { + path = path.SetQueryParam("since", opts.Since); + } + + var data = _client.ExecuteList>(path, opts); + + return data; + } + + /// + /// Gets a list of recently modified deals + /// + /// Implementation of DealListHubSpotModel + /// Options (limit, offset) relating to request + /// List of deals + public DealRecentListHubSpotModel RecentlyUpdated(DealRecentRequestOptions opts = null) where T : DealHubSpotModel, new() + { + if (opts == null) + { + opts = new DealRecentRequestOptions(); + } + + var path = $"{new DealRecentListHubSpotModel().RouteBasePath}/deal/recent/modified" + .SetQueryParam("limit", opts.Limit); + + if (opts.Offset.HasValue) + { + path = path.SetQueryParam("offset", opts.Offset); + } + + if (opts.IncludePropertyVersion) + { + path = path.SetQueryParam("includePropertyVersions", "true"); + } + + if (!string.IsNullOrEmpty(opts.Since)) + { + path = path.SetQueryParam("since", opts.Since); + } + + var data = _client.ExecuteList>(path, opts); + + return data; + } } } diff --git a/HubSpot.NET/Core/Interfaces/IHubSpotDealApi.cs b/HubSpot.NET/Core/Interfaces/IHubSpotDealApi.cs index 429beee5..b8868acc 100644 --- a/HubSpot.NET/Core/Interfaces/IHubSpotDealApi.cs +++ b/HubSpot.NET/Core/Interfaces/IHubSpotDealApi.cs @@ -12,5 +12,11 @@ public interface IHubSpotDealApi DealListHubSpotModel List(bool includeAssociations, ListRequestOptions opts = null) where T : DealHubSpotModel, new(); + + DealRecentListHubSpotModel RecentlyCreated(DealRecentRequestOptions opts = null) + where T : DealHubSpotModel, new(); + + DealRecentListHubSpotModel RecentlyUpdated(DealRecentRequestOptions opts = null) + where T : DealHubSpotModel, new(); } } \ No newline at end of file