Skip to content

Commit fc1826e

Browse files
authored
Merge pull request #2 from andreasobjektvision/Pull01
Listing of custom subclasses of hubspotmodel
2 parents e59ae50 + 2e233ac commit fc1826e

23 files changed

+121
-61
lines changed

HubSpot.NET.Examples/Companies.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static void Example()
3737
/**
3838
* Get all companies with domain name "squaredup.com"
3939
*/
40-
var companies = api.Company.GetByDomain<CompanySearchResultModel>("squaredup.com", new CompanySearchByDomain()
40+
var companies = api.Company.GetByDomain<CompanyHubSpotModel>("squaredup.com", new CompanySearchByDomain()
4141
{
4242
Limit = 10
4343
});

HubSpot.NET.Examples/Contacts.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public static void Example()
4646
Hidden = true, //set to true for engagements
4747
};
4848

49-
var uploaded = api.File.Upload(file);
49+
var uploaded = api.File.Upload<FileHubSpotModel>(file);
5050
var fileId = uploaded.Objects.First().Id;
5151

5252
/**
@@ -83,12 +83,8 @@ public static void Example()
8383
* Get all contacts with specific properties
8484
* By default only a few properties are returned
8585
*/
86-
var contacts = api.Contact.List<ContactListHubSpotModel>(new List<string>
87-
{
88-
"firstname",
89-
"lastname",
90-
"email"
91-
});
86+
var contacts = api.Contact.List<ContactHubSpotModel>(
87+
new ListRequestOptions { PropertiesToInclude = new List<string> { "firstname", "lastname", "email" } });
9288
}
9389
}
9490
}

HubSpot.NET.Examples/Deals.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,8 @@ public static void Example()
3131
/**
3232
* Get all deals
3333
*/
34-
var deals = api.Deal.List<DealListHubSpotModel>(new List<string>
35-
{
36-
"dealname", "amount"
37-
}, false);
34+
var deals = api.Deal.List<DealHubSpotModel>(false,
35+
new ListRequestOptions { PropertiesToInclude = new List<string> { "dealname", "amount" } });
3836
}
3937
}
4038
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using HubSpot.NET.Core.Interfaces;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Runtime.Serialization;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace HubSpot.NET.Api.Company.Dto
10+
{
11+
public class CompanyListHubSpotModel<T> : IHubSpotModel where T: CompanyHubSpotModel, new()
12+
{
13+
[DataMember(Name = "companies")]
14+
public IList<T> Companies { get; set; } = new List<T>();
15+
16+
public bool IsNameValue => false;
17+
18+
public string RouteBasePath => "/companies/v2";
19+
20+
[DataMember(Name = "has-more")]
21+
public bool MoreResultsAvailable { get; set; }
22+
23+
[DataMember(Name = "offset")]
24+
public long ContinuationOffset { get; set; }
25+
26+
27+
public void FromHubSpotDataEntity(dynamic hubspotData)
28+
{
29+
}
30+
31+
public void ToHubSpotDataEntity(ref dynamic dataEntity)
32+
{
33+
}
34+
}
35+
}

HubSpot.NET/Api/Company/Dto/CompanySearchResultModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ namespace HubSpot.NET.Api.Company.Dto
88
/// Models a set of results returned from the companies endpoint.
99
/// </summary>
1010
[DataContract]
11-
public class CompanySearchResultModel : IHubSpotModel
11+
public class CompanySearchResultModel<T> : IHubSpotModel where T: CompanyHubSpotModel, new()
1212
{
1313
[DataMember(Name = "results")]
14-
public IList<CompanyHubSpotModel> Results { get; set; }
14+
public IList<T> Results { get; set; }
1515

1616
[DataMember(Name = "hasMore")]
1717
public bool MoreResultsAvailable { get; set; }

HubSpot.NET/Api/Company/HubSpotCompanyApi.cs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
using System;
2+
using System.Linq;
3+
using Flurl;
24
using HubSpot.NET.Api.Company.Dto;
5+
using HubSpot.NET.Core;
36
using HubSpot.NET.Core.Interfaces;
47
using RestSharp;
58

@@ -48,7 +51,7 @@ public HubSpotCompanyApi(IHubSpotClient client)
4851
/// <param name="domain">Domain name to search for</param>
4952
/// <param name="options">Set of search options</param>
5053
/// <returns>The company entity</returns>
51-
public T GetByDomain<T>(string domain, CompanySearchByDomain options = null) where T : CompanySearchResultModel, new()
54+
public CompanySearchResultModel<T> GetByDomain<T>(string domain, CompanySearchByDomain options = null) where T : CompanyHubSpotModel, new()
5255
{
5356
if (options == null)
5457
{
@@ -57,7 +60,31 @@ public HubSpotCompanyApi(IHubSpotClient client)
5760

5861
var path = $"{new CompanyHubSpotModel().RouteBasePath}/domains/{domain}/companies";
5962

60-
var data = _client.ExecuteList<T>(path, options, Method.POST);
63+
var data = _client.ExecuteList<CompanySearchResultModel<T>>(path, options, Method.POST);
64+
65+
return data;
66+
}
67+
68+
public CompanyListHubSpotModel<T> List<T>(ListRequestOptions opts = null) where T: CompanyHubSpotModel, new()
69+
{
70+
if (opts == null)
71+
{
72+
opts = new ListRequestOptions();
73+
}
74+
75+
var path = $"{new CompanyHubSpotModel().RouteBasePath}/companies/paged"
76+
.SetQueryParam("count", opts.Limit);
77+
78+
if (opts.PropertiesToInclude.Any())
79+
{
80+
path.SetQueryParam("properties", opts.PropertiesToInclude);
81+
}
82+
if (opts.Offset.HasValue)
83+
{
84+
path = path.SetQueryParam("offset", opts.Offset);
85+
}
86+
87+
var data = _client.ExecuteList<CompanyListHubSpotModel<T>>(path, opts);
6188

6289
return data;
6390
}

HubSpot.NET/Api/Contact/Dto/ContactListHubSpotModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace HubSpot.NET.Api.Contact.Dto
88
/// Models a set of results returned when querying for sets of contacts
99
/// </summary>
1010
[DataContract]
11-
public class ContactListHubSpotModel : IHubSpotModel
11+
public class ContactListHubSpotModel<T> : IHubSpotModel where T: ContactHubSpotModel, new()
1212
{
1313
/// <summary>
1414
/// Gets or sets the contacts.
@@ -17,7 +17,7 @@ public class ContactListHubSpotModel : IHubSpotModel
1717
/// The contacts.
1818
/// </value>
1919
[DataMember(Name = "contacts")]
20-
public IList<ContactHubSpotModel> Contacts { get; set; } = new List<ContactHubSpotModel>();
20+
public IList<T> Contacts { get; set; } = new List<T>();
2121

2222
/// <summary>
2323
/// Gets or sets a value indicating whether more results are available.

HubSpot.NET/Api/Contact/HubSpotContactApi.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public HubSpotContactApi(IHubSpotClient client)
6464
/// <param name="opts">Request options - used for pagination etc.</param>
6565
/// <typeparam name="T">Implementation of ContactHubSpotModel</typeparam>
6666
/// <returns>A list of contacts</returns>
67-
public T List<T>(List<string> properties, ListRequestOptions opts = null) where T : ContactListHubSpotModel, new()
67+
public ContactListHubSpotModel<T> List<T>(ListRequestOptions opts = null) where T : ContactHubSpotModel, new()
6868
{
6969
if (opts == null)
7070
{
@@ -74,17 +74,17 @@ public HubSpotContactApi(IHubSpotClient client)
7474
var path = $"{new ContactHubSpotModel().RouteBasePath}/lists/all/contacts/all"
7575
.SetQueryParam("count", opts.Limit);
7676

77-
if (opts.Offset.HasValue)
77+
if (opts.PropertiesToInclude.Any())
7878
{
79-
path = path.SetQueryParam("vidOffset", opts.Offset);
79+
path.SetQueryParam("property", opts.PropertiesToInclude);
8080
}
8181

82-
if (properties != null && properties.Any())
82+
if (opts.Offset.HasValue)
8383
{
84-
path = path.SetQueryParam("property", properties);
84+
path = path.SetQueryParam("vidOffset", opts.Offset);
8585
}
8686

87-
var data = _client.ExecuteList<T>(path, opts);
87+
var data = _client.ExecuteList<ContactListHubSpotModel<T>>(path, opts);
8888

8989
return data;
9090
}

HubSpot.NET/Api/Deal/Dto/DealListHubSpotModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace HubSpot.NET.Api.Deal.Dto
99
/// Models a set of results returned when querying for sets of deals
1010
/// </summary>
1111
[DataContract]
12-
public class DealListHubSpotModel : IHubSpotModel
12+
public class DealListHubSpotModel<T> : IHubSpotModel where T: DealHubSpotModel, new()
1313
{
1414
/// <summary>
1515
/// Gets or sets the deals.

HubSpot.NET/Api/Deal/HubSpotDealApi.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ public HubSpotDealApi(IHubSpotClient client)
6969
/// <typeparam name="T">Implementation of DealListHubSpotModel</typeparam>
7070
/// <param name="opts">Options (limit, offset) relating to request</param>
7171
/// <returns>List of deals</returns>
72-
public T List<T>(List<string> properties, bool includeAssociations, ListRequestOptions opts = null) where T : DealListHubSpotModel, new()
72+
public DealListHubSpotModel<T> List<T>(bool includeAssociations, ListRequestOptions opts = null) where T : DealHubSpotModel, new()
7373
{
7474
if (opts == null)
7575
{
7676
opts = new ListRequestOptions();
7777
}
7878

79-
var path = $"{new DealListHubSpotModel().RouteBasePath}/deal/paged"
79+
var path = $"{new DealListHubSpotModel<T>().RouteBasePath}/deal/paged"
8080
.SetQueryParam("limit", opts.Limit);
8181

8282
if (opts.Offset.HasValue)
@@ -89,12 +89,12 @@ public HubSpotDealApi(IHubSpotClient client)
8989
path = path.SetQueryParam("includeAssocations", "true");
9090
}
9191

92-
if (properties != null && properties.Any())
92+
if (opts.PropertiesToInclude.Any())
9393
{
94-
path = path.SetQueryParam("properties", properties);
94+
path = path.SetQueryParam("properties", opts.PropertiesToInclude);
9595
}
9696

97-
var data = _client.ExecuteList<T>(path, opts);
97+
var data = _client.ExecuteList<DealListHubSpotModel<T>>(path, opts);
9898

9999
return data;
100100
}

0 commit comments

Comments
 (0)