Skip to content

Commit

Permalink
Merge pull request #2 from andreasobjektvision/Pull01
Browse files Browse the repository at this point in the history
Listing of custom subclasses of hubspotmodel
  • Loading branch information
clarkd authored Feb 24, 2018
2 parents e59ae50 + 2e233ac commit fc1826e
Show file tree
Hide file tree
Showing 23 changed files with 121 additions and 61 deletions.
2 changes: 1 addition & 1 deletion HubSpot.NET.Examples/Companies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static void Example()
/**
* Get all companies with domain name "squaredup.com"
*/
var companies = api.Company.GetByDomain<CompanySearchResultModel>("squaredup.com", new CompanySearchByDomain()
var companies = api.Company.GetByDomain<CompanyHubSpotModel>("squaredup.com", new CompanySearchByDomain()
{
Limit = 10
});
Expand Down
10 changes: 3 additions & 7 deletions HubSpot.NET.Examples/Contacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static void Example()
Hidden = true, //set to true for engagements
};

var uploaded = api.File.Upload(file);
var uploaded = api.File.Upload<FileHubSpotModel>(file);
var fileId = uploaded.Objects.First().Id;

/**
Expand Down Expand Up @@ -83,12 +83,8 @@ public static void Example()
* Get all contacts with specific properties
* By default only a few properties are returned
*/
var contacts = api.Contact.List<ContactListHubSpotModel>(new List<string>
{
"firstname",
"lastname",
"email"
});
var contacts = api.Contact.List<ContactHubSpotModel>(
new ListRequestOptions { PropertiesToInclude = new List<string> { "firstname", "lastname", "email" } });
}
}
}
6 changes: 2 additions & 4 deletions HubSpot.NET.Examples/Deals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ public static void Example()
/**
* Get all deals
*/
var deals = api.Deal.List<DealListHubSpotModel>(new List<string>
{
"dealname", "amount"
}, false);
var deals = api.Deal.List<DealHubSpotModel>(false,
new ListRequestOptions { PropertiesToInclude = new List<string> { "dealname", "amount" } });
}
}
}
35 changes: 35 additions & 0 deletions HubSpot.NET/Api/Company/Dto/CompanyListHubSpotModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using HubSpot.NET.Core.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace HubSpot.NET.Api.Company.Dto
{
public class CompanyListHubSpotModel<T> : IHubSpotModel where T: CompanyHubSpotModel, new()
{
[DataMember(Name = "companies")]
public IList<T> Companies { get; set; } = new List<T>();

public bool IsNameValue => false;

public string RouteBasePath => "/companies/v2";

[DataMember(Name = "has-more")]
public bool MoreResultsAvailable { get; set; }

[DataMember(Name = "offset")]
public long ContinuationOffset { get; set; }


public void FromHubSpotDataEntity(dynamic hubspotData)
{
}

public void ToHubSpotDataEntity(ref dynamic dataEntity)
{
}
}
}
4 changes: 2 additions & 2 deletions HubSpot.NET/Api/Company/Dto/CompanySearchResultModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ namespace HubSpot.NET.Api.Company.Dto
/// Models a set of results returned from the companies endpoint.
/// </summary>
[DataContract]
public class CompanySearchResultModel : IHubSpotModel
public class CompanySearchResultModel<T> : IHubSpotModel where T: CompanyHubSpotModel, new()
{
[DataMember(Name = "results")]
public IList<CompanyHubSpotModel> Results { get; set; }
public IList<T> Results { get; set; }

[DataMember(Name = "hasMore")]
public bool MoreResultsAvailable { get; set; }
Expand Down
31 changes: 29 additions & 2 deletions HubSpot.NET/Api/Company/HubSpotCompanyApi.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using System;
using System.Linq;
using Flurl;
using HubSpot.NET.Api.Company.Dto;
using HubSpot.NET.Core;
using HubSpot.NET.Core.Interfaces;
using RestSharp;

Expand Down Expand Up @@ -48,7 +51,7 @@ public HubSpotCompanyApi(IHubSpotClient client)
/// <param name="domain">Domain name to search for</param>
/// <param name="options">Set of search options</param>
/// <returns>The company entity</returns>
public T GetByDomain<T>(string domain, CompanySearchByDomain options = null) where T : CompanySearchResultModel, new()
public CompanySearchResultModel<T> GetByDomain<T>(string domain, CompanySearchByDomain options = null) where T : CompanyHubSpotModel, new()
{
if (options == null)
{
Expand All @@ -57,7 +60,31 @@ public HubSpotCompanyApi(IHubSpotClient client)

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

var data = _client.ExecuteList<T>(path, options, Method.POST);
var data = _client.ExecuteList<CompanySearchResultModel<T>>(path, options, Method.POST);

return data;
}

public CompanyListHubSpotModel<T> List<T>(ListRequestOptions opts = null) where T: CompanyHubSpotModel, new()
{
if (opts == null)
{
opts = new ListRequestOptions();
}

var path = $"{new CompanyHubSpotModel().RouteBasePath}/companies/paged"
.SetQueryParam("count", opts.Limit);

if (opts.PropertiesToInclude.Any())
{
path.SetQueryParam("properties", opts.PropertiesToInclude);
}
if (opts.Offset.HasValue)
{
path = path.SetQueryParam("offset", opts.Offset);
}

var data = _client.ExecuteList<CompanyListHubSpotModel<T>>(path, opts);

return data;
}
Expand Down
4 changes: 2 additions & 2 deletions HubSpot.NET/Api/Contact/Dto/ContactListHubSpotModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace HubSpot.NET.Api.Contact.Dto
/// Models a set of results returned when querying for sets of contacts
/// </summary>
[DataContract]
public class ContactListHubSpotModel : IHubSpotModel
public class ContactListHubSpotModel<T> : IHubSpotModel where T: ContactHubSpotModel, new()
{
/// <summary>
/// Gets or sets the contacts.
Expand All @@ -17,7 +17,7 @@ public class ContactListHubSpotModel : IHubSpotModel
/// The contacts.
/// </value>
[DataMember(Name = "contacts")]
public IList<ContactHubSpotModel> Contacts { get; set; } = new List<ContactHubSpotModel>();
public IList<T> Contacts { get; set; } = new List<T>();

/// <summary>
/// Gets or sets a value indicating whether more results are available.
Expand Down
12 changes: 6 additions & 6 deletions HubSpot.NET/Api/Contact/HubSpotContactApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public HubSpotContactApi(IHubSpotClient client)
/// <param name="opts">Request options - used for pagination etc.</param>
/// <typeparam name="T">Implementation of ContactHubSpotModel</typeparam>
/// <returns>A list of contacts</returns>
public T List<T>(List<string> properties, ListRequestOptions opts = null) where T : ContactListHubSpotModel, new()
public ContactListHubSpotModel<T> List<T>(ListRequestOptions opts = null) where T : ContactHubSpotModel, new()
{
if (opts == null)
{
Expand All @@ -74,17 +74,17 @@ public HubSpotContactApi(IHubSpotClient client)
var path = $"{new ContactHubSpotModel().RouteBasePath}/lists/all/contacts/all"
.SetQueryParam("count", opts.Limit);

if (opts.Offset.HasValue)
if (opts.PropertiesToInclude.Any())
{
path = path.SetQueryParam("vidOffset", opts.Offset);
path.SetQueryParam("property", opts.PropertiesToInclude);
}

if (properties != null && properties.Any())
if (opts.Offset.HasValue)
{
path = path.SetQueryParam("property", properties);
path = path.SetQueryParam("vidOffset", opts.Offset);
}

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

return data;
}
Expand Down
2 changes: 1 addition & 1 deletion HubSpot.NET/Api/Deal/Dto/DealListHubSpotModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace HubSpot.NET.Api.Deal.Dto
/// Models a set of results returned when querying for sets of deals
/// </summary>
[DataContract]
public class DealListHubSpotModel : IHubSpotModel
public class DealListHubSpotModel<T> : IHubSpotModel where T: DealHubSpotModel, new()
{
/// <summary>
/// Gets or sets the deals.
Expand Down
10 changes: 5 additions & 5 deletions HubSpot.NET/Api/Deal/HubSpotDealApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ public HubSpotDealApi(IHubSpotClient client)
/// <typeparam name="T">Implementation of DealListHubSpotModel</typeparam>
/// <param name="opts">Options (limit, offset) relating to request</param>
/// <returns>List of deals</returns>
public T List<T>(List<string> properties, bool includeAssociations, ListRequestOptions opts = null) where T : DealListHubSpotModel, new()
public DealListHubSpotModel<T> List<T>(bool includeAssociations, ListRequestOptions opts = null) where T : DealHubSpotModel, new()
{
if (opts == null)
{
opts = new ListRequestOptions();
}

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

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

if (properties != null && properties.Any())
if (opts.PropertiesToInclude.Any())
{
path = path.SetQueryParam("properties", properties);
path = path.SetQueryParam("properties", opts.PropertiesToInclude);
}

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

return data;
}
Expand Down
4 changes: 2 additions & 2 deletions HubSpot.NET/Api/Engagement/Dto/EngagementListHubSpotModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace HubSpot.NET.Api.Engagement.Dto
/// Models a set of engagements returned by the API
/// </summary>
[DataContract]
public class EngagementListHubSpotModel : IHubSpotModel
public class EngagementListHubSpotModel<T> : IHubSpotModel where T: EngagementHubSpotModel, new()
{
/// <summary>
/// Gets or sets the contacts.
Expand All @@ -17,7 +17,7 @@ public class EngagementListHubSpotModel : IHubSpotModel
/// The contacts.
/// </value>
[DataMember(Name = "results")]
public IList<EngagementHubSpotModel> Engagements { get; set; } = new List<EngagementHubSpotModel>();
public IList<T> Engagements { get; set; } = new List<T>();

/// <summary>
/// Gets or sets a value indicating whether more results are available.
Expand Down
12 changes: 6 additions & 6 deletions HubSpot.NET/Api/Engagement/HubSpotEngagementApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public EngagementHubSpotModel GetById(long engagementId)
/// </summary>
/// <param name="opts">Options for querying</param>
/// <returns>List of engagements, with additional metadata, e.g. total</returns>
public EngagementListHubSpotModel List(EngagementListRequestOptions opts = null)
public EngagementListHubSpotModel<T> List<T>(EngagementListRequestOptions opts = null) where T: EngagementHubSpotModel, new()
{
if (opts == null)
{
Expand All @@ -75,7 +75,7 @@ public EngagementListHubSpotModel List(EngagementListRequestOptions opts = null)
path = path.SetQueryParam("offset", opts.Offset);
}

var data = _client.ExecuteList<EngagementListHubSpotModel>(path, opts, convertToPropertiesSchema: false);
var data = _client.ExecuteList<EngagementListHubSpotModel<T>>(path, opts, convertToPropertiesSchema: false);
return data;
}

Expand All @@ -84,7 +84,7 @@ public EngagementListHubSpotModel List(EngagementListRequestOptions opts = null)
/// </summary>
/// <param name="opts">Options for querying</param>
/// <returns>List of engagements, with additional metadata, e.g. total</returns>
public EngagementListHubSpotModel ListRecent(EngagementListRequestOptions opts = null)
public EngagementListHubSpotModel<T> ListRecent<T>(EngagementListRequestOptions opts = null) where T : EngagementHubSpotModel, new()
{
if (opts == null)
{
Expand All @@ -97,7 +97,7 @@ public EngagementListHubSpotModel ListRecent(EngagementListRequestOptions opts =
path = path.SetQueryParam("offset", opts.Offset);
}

var data = _client.ExecuteList<EngagementListHubSpotModel>(path, opts, convertToPropertiesSchema: false);
var data = _client.ExecuteList<EngagementListHubSpotModel<T>>(path, opts, convertToPropertiesSchema: false);
return data;
}

Expand Down Expand Up @@ -132,7 +132,7 @@ public void Associate(long engagementId, string objectType, long objectId)
/// <param name="objectType">The object type, e.g. CONTACT</param>
/// <param name="opts">Options used for querying</param>
/// <returns>List of associated engagements</returns>
public EngagementListHubSpotModel ListAssociated(long objectId, string objectType, EngagementListRequestOptions opts = null)
public EngagementListHubSpotModel<T> ListAssociated<T>(long objectId, string objectType, EngagementListRequestOptions opts = null) where T: EngagementHubSpotModel, new()
{
if (opts == null)
{
Expand All @@ -145,7 +145,7 @@ public EngagementListHubSpotModel ListAssociated(long objectId, string objectTyp
path = path.SetQueryParam("offset", opts.Offset);
}

var data = _client.ExecuteList<EngagementListHubSpotModel>(path, opts, convertToPropertiesSchema: false);
var data = _client.ExecuteList<EngagementListHubSpotModel<T>>(path, opts, convertToPropertiesSchema: false);
return data;
}

Expand Down
4 changes: 2 additions & 2 deletions HubSpot.NET/Api/Files/Dto/FileListHubSpotModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ namespace HubSpot.NET.Api.Files.Dto
/// <summary>
/// Models a list of files
/// </summary>
public class FileListHubSpotModel : IHubSpotModel
public class FileListHubSpotModel<T> : IHubSpotModel where T: FileHubSpotModel, new()
{
[DataMember(Name="objects")]
public List<FileHubSpotModel> Objects { get;set; }
public List<T> Objects { get;set; }

public bool IsNameValue { get; }

Expand Down
4 changes: 2 additions & 2 deletions HubSpot.NET/Api/Files/HubSpotCosFileApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ public HubSpotCosFileApi(IHubSpotClient client)
/// </summary>
/// <param name="entity">The file to upload</param>
/// <returns>The uploaded file</returns>
public FileListHubSpotModel Upload(FileHubSpotModel entity)
public FileListHubSpotModel<T> Upload<T>(FileHubSpotModel entity) where T: FileHubSpotModel, new()
{
var path = $"{new FileHubSpotModel().RouteBasePath}/files";
var data = _client.ExecuteMultipart<FileListHubSpotModel>(path, entity.File, entity.Name,
var data = _client.ExecuteMultipart<FileListHubSpotModel<T>>(path, entity.File, entity.Name,
new Dictionary<string, string>()
{
{"overwrite", entity.Overwrite.ToString()},
Expand Down
14 changes: 7 additions & 7 deletions HubSpot.NET/Api/Owner/Dto/OwnerListHubSpotModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ namespace HubSpot.NET.Api.Owner.Dto
/// Models a set of owners in HubSpot
/// </summary>
[DataContract]
public class OwnerListHubSpotModel : IHubSpotModel, ICollection<OwnerHubSpotModel>
public class OwnerListHubSpotModel<T> : IHubSpotModel, ICollection<T> where T: OwnerHubSpotModel, new()
{
private List<OwnerHubSpotModel> Owners { get; } = new List<OwnerHubSpotModel>();
private List<T> Owners { get; } = new List<T>();

public string RouteBasePath => "/owners/v2";

Expand All @@ -25,7 +25,7 @@ public virtual void FromHubSpotDataEntity(dynamic hubspotData)
{
}

public IEnumerator<OwnerHubSpotModel> GetEnumerator()
public IEnumerator<T> GetEnumerator()
{
return Owners.GetEnumerator();
}
Expand All @@ -35,7 +35,7 @@ IEnumerator IEnumerable.GetEnumerator()
return GetEnumerator();
}

public void Add(OwnerHubSpotModel item)
public void Add(T item)
{
Owners.Add(item);
}
Expand All @@ -45,17 +45,17 @@ public void Clear()
Owners.Clear();
}

public bool Contains(OwnerHubSpotModel item)
public bool Contains(T item)
{
return Owners.Contains(item);
}

public void CopyTo(OwnerHubSpotModel[] array, int arrayIndex)
public void CopyTo(T[] array, int arrayIndex)
{
Owners.CopyTo(array, arrayIndex);
}

public bool Remove(OwnerHubSpotModel item)
public bool Remove(T item)
{
return Owners.Remove(item);
}
Expand Down
Loading

0 comments on commit fc1826e

Please sign in to comment.