From 9888785783c64dc637bab7cb0551aee901102e8c Mon Sep 17 00:00:00 2001 From: Brian Futrell Date: Wed, 2 May 2018 11:11:11 -0400 Subject: [PATCH 1/4] added recently created and modified deals --- HubSpot.NET.Examples/Deals.cs | 22 +++++- HubSpot.NET/Api/Company/HubSpotCompanyApi.cs | 61 ++++++++++++++++ .../Deal/Dto/DealRecentListHubSpotModel.cs | 28 +++++++ .../Api/Deal/Dto/DealRecentRequestOptions.cs | 22 ++++++ HubSpot.NET/Api/Deal/HubSpotDealApi.cs | 73 +++++++++++++++++++ .../Core/Interfaces/IHubSpotDealApi.cs | 6 ++ 6 files changed, 211 insertions(+), 1 deletion(-) create mode 100644 HubSpot.NET/Api/Deal/Dto/DealRecentListHubSpotModel.cs create mode 100644 HubSpot.NET/Api/Deal/Dto/DealRecentRequestOptions.cs diff --git a/HubSpot.NET.Examples/Deals.cs b/HubSpot.NET.Examples/Deals.cs index ff938084..05f98105 100644 --- a/HubSpot.NET.Examples/Deals.cs +++ b/HubSpot.NET.Examples/Deals.cs @@ -36,6 +36,7 @@ public static void Example() /** * Get all deals + * This is commented in case the data has a large quantity of deals in HubSpot. */ //var moreResults = true; //long offset = 0; @@ -46,8 +47,27 @@ public static void Example() // moreResults = allDeals.MoreResultsAvailable; // if (moreResults) offset = allDeals.ContinuationOffset; - //} + + /** + * Get recently created deals, limited to 10 records + * Using DealRecentListHubSpotModel to accomodate deals returning in the "results" property. + */ + var recentlyCreatedDeals = api.Deal.RecentlyCreated(new DealRecentRequestOptions + { + Limit = 10, + IncludePropertyVersion = false, + }); + + /** + * Get recently created deals, limited to 10 records + * Using DealRecentListHubSpotModel to accomodate deals returning in the "results" property. + */ + var recentlyUpdatedDeals = api.Deal.RecentlyCreated(new DealRecentRequestOptions + { + Limit = 10, + IncludePropertyVersion = false, + }); } } } diff --git a/HubSpot.NET/Api/Company/HubSpotCompanyApi.cs b/HubSpot.NET/Api/Company/HubSpotCompanyApi.cs index 9b13573f..6503adbb 100644 --- a/HubSpot.NET/Api/Company/HubSpotCompanyApi.cs +++ b/HubSpot.NET/Api/Company/HubSpotCompanyApi.cs @@ -119,5 +119,66 @@ public void Delete(long companyId) _client.Execute(path, method: Method.DELETE); } + + 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; + } + + 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; + } } } \ 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 From a94935b6ea0bcefb4d1cc5af989aa824b1542bfe Mon Sep 17 00:00:00 2001 From: Brian Futrell Date: Wed, 2 May 2018 11:25:45 -0400 Subject: [PATCH 2/4] added code to pass in Since value for recently created and modified deals --- HubSpot.NET.Examples/Deals.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/HubSpot.NET.Examples/Deals.cs b/HubSpot.NET.Examples/Deals.cs index 05f98105..f813f291 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,7 +37,7 @@ public static void Example() /** * Get all deals - * This is commented in case the data has a large quantity of deals in HubSpot. + * This is commented in case the HubSpot data has a large quantity of deals. */ //var moreResults = true; //long offset = 0; @@ -50,23 +51,28 @@ public static void Example() //} /** - * Get recently created deals, limited to 10 records + * Get recently created deals since 7 days ago, limited to 10 records * 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, limited to 10 records + * Get recently created deals since 7 days ago, limited to 10 records * Using DealRecentListHubSpotModel to accomodate deals returning in the "results" property. */ var recentlyUpdatedDeals = api.Deal.RecentlyCreated(new DealRecentRequestOptions { Limit = 10, IncludePropertyVersion = false, + Since = since }); } } From 608af1175c85318930002a9a1d2b1461712c9c49 Mon Sep 17 00:00:00 2001 From: Brian Futrell Date: Wed, 2 May 2018 11:30:55 -0400 Subject: [PATCH 3/4] removed misplaced deals methods from company API class --- HubSpot.NET/Api/Company/HubSpotCompanyApi.cs | 62 +------------------- 1 file changed, 1 insertion(+), 61 deletions(-) diff --git a/HubSpot.NET/Api/Company/HubSpotCompanyApi.cs b/HubSpot.NET/Api/Company/HubSpotCompanyApi.cs index 6503adbb..65cb0787 100644 --- a/HubSpot.NET/Api/Company/HubSpotCompanyApi.cs +++ b/HubSpot.NET/Api/Company/HubSpotCompanyApi.cs @@ -119,66 +119,6 @@ public void Delete(long companyId) _client.Execute(path, method: Method.DELETE); } - - 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; - } - - 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; - } + } } \ No newline at end of file From 4e2297c27c9621af9e9d7255fa650272da89cac5 Mon Sep 17 00:00:00 2001 From: Brian Futrell Date: Wed, 2 May 2018 11:39:37 -0400 Subject: [PATCH 4/4] note added about default number of days if Since property is not set --- HubSpot.NET.Examples/Deals.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/HubSpot.NET.Examples/Deals.cs b/HubSpot.NET.Examples/Deals.cs index f813f291..965b0449 100644 --- a/HubSpot.NET.Examples/Deals.cs +++ b/HubSpot.NET.Examples/Deals.cs @@ -52,6 +52,7 @@ public static void Example() /** * 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); @@ -66,6 +67,7 @@ public static void Example() /** * 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