diff --git a/src/Core/HubSpotAction.cs b/src/Core/HubSpotAction.cs index cb5acd6..e7f6216 100644 --- a/src/Core/HubSpotAction.cs +++ b/src/Core/HubSpotAction.cs @@ -1,4 +1,4 @@ -namespace Skarp.HubSpotClient.Core +namespace Skarp.HubSpotClient.Core { /// /// Enumerates the possible actions against the hubspot api @@ -25,6 +25,8 @@ public enum HubSpotAction UpdateBatch, - ReadBatch + ReadBatch, + + Lists } -} \ No newline at end of file +} diff --git a/src/ListOfContacts/Dto/ListOfContactListsHubSpotEntity.cs b/src/ListOfContacts/Dto/ListOfContactListsHubSpotEntity.cs new file mode 100644 index 0000000..573a7a3 --- /dev/null +++ b/src/ListOfContacts/Dto/ListOfContactListsHubSpotEntity.cs @@ -0,0 +1,92 @@ +using Newtonsoft.Json; +using Skarp.HubSpotClient.Core.Interfaces; +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; +using System.Text; + +namespace Skarp.HubSpotClient.ListOfContacts.Dto +{ + public class ListOfContactListsHubSpotEntity: IHubSpotEntity + { + [DataContract(Name="MetaData")] + public class ContactListsMetaData + { + [DataMember(Name="processing")] + public string Processing { get; set; } + [DataMember(Name="size")] + public int Size { get; set; } + [DataMember(Name="error")] + public string Error { get; set; } + [DataMember(Name="lastProcessingStateChangeAt")] + public long LastProcessingStateChangeAtTimeStamp { get; set; } + [DataMember(Name="lastSizeChangeAt")] + public long LastSizeChangeAtTimeStamp { get; set; } + } + + [DataContract(Name="List")] + public class ContactListsItem + { + [DataMember(Name="dynamic")] + public bool Dynamic { get; set; } + [DataMember(Name="metaData")] + public ContactListsMetaData MetaData { get; set; } + [DataMember(Name="name")] + public string Name { get; set; } + [DataMember(Name="filters")] + public List> Filters { get; set; } + [DataMember(Name="portalId")] + public int PortalId { get; set; } + [DataMember(Name="createdAt")] + public long CreatedAtTimeStamp { get; set; } + [DataMember(Name="listId")] + public int ListId { get; set; } + [DataMember(Name="updatedAt")] + public long UpdatedAtTimeStamp { get; set; } + [DataMember(Name="listType")] + public string ListType { get; set; } + [DataMember(Name="internalListId")] + public int InternalListId { get; set; } + [DataMember(Name="deleteable")] + public bool Deleteable { get; set; } + } + + [DataContract(Name="filter")] + public class ContactListsFilter + { + [DataMember(Name="filterFamily")] + public string FilterFamily { get; set; } + [DataMember(Name="withinTimeMode")] + public string WithinTimeMode { get; set; } + [DataMember(Name="checkPastVersions")] + public bool CheckPastVersions { get; set; } + [DataMember(Name="type")] + public string Type { get; set; } + [DataMember(Name="property")] + public string Property { get; set; } + [DataMember(Name="value")] + public string Value { get; set; } + [DataMember(Name = "operator")] + public string op { get; set; } + } + + + public List lists { get; set; } + public int offset { get; set; } + + [DataMember(Name = "has-more")] + public bool HasMore { get; set; } + + public bool IsNameValue => false; + + public virtual void ToHubSpotDataEntity(ref dynamic dataEntity) + { + + } + + public virtual void FromHubSpotDataEntity(dynamic hubspotData) + { + + } + } +} diff --git a/src/ListOfContacts/HubSpotListOfContactsClient.cs b/src/ListOfContacts/HubSpotListOfContactsClient.cs index 3217c3d..bfd7d47 100644 --- a/src/ListOfContacts/HubSpotListOfContactsClient.cs +++ b/src/ListOfContacts/HubSpotListOfContactsClient.cs @@ -73,6 +73,28 @@ public async Task GetListByIdAsync(long listId, ListOfContactsRequestOptio return data; } + /// + /// Return a list of contact lists from hubspot + /// + /// + /// + public async Task GetListAsync(ListOfContactListsRequestOptions opts = null) + { + Logger.LogDebug("Get list of contact lists"); + if (opts == null) + { + opts = new ListOfContactListsRequestOptions(); + } + var path = PathResolver(new ContactHubSpotEntity(), HubSpotAction.Lists) + .SetQueryParam("count", opts.NumberOfContactListsToReturn); + if (opts.ContactListOffset.HasValue) + { + path = path.SetQueryParam("vidOffset", opts.ContactListOffset); + } + var data = await GetGenericAsync(path); + return data; + } + /// /// Add list of contacts based on list id /// @@ -116,6 +138,8 @@ public string PathResolver(Contact.Interfaces.IContactHubSpotEntity entity, HubS { case HubSpotAction.Get: return $"{entity.RouteBasePath}/lists/:listId:/contacts/all"; + case HubSpotAction.Lists: + return $"{entity.RouteBasePath}/lists"; case HubSpotAction.CreateBatch: return $"{entity.RouteBasePath}/lists/:listId:/add"; case HubSpotAction.DeleteBatch: diff --git a/src/ListOfContacts/ListOfContactListsRequestOptions.cs b/src/ListOfContacts/ListOfContactListsRequestOptions.cs new file mode 100644 index 0000000..55120bd --- /dev/null +++ b/src/ListOfContacts/ListOfContactListsRequestOptions.cs @@ -0,0 +1,41 @@ +using System; + +namespace Skarp.HubSpotClient.ListOfContacts +{ + public class ListOfContactListsRequestOptions + { + private int _numberOfContactListsToReturn = 100; + + /// + /// Gets or sets the number of contact lists to return. + /// + /// + /// Defaults to 20 which is also the hubspot api default. Max value is 100 + /// + /// + /// The number of contacts to return. + /// + public int NumberOfContactListsToReturn + { + get => _numberOfContactListsToReturn; + set + { + if (value < 1 || value > 250) + { + throw new ArgumentException( + $"Number of contacts to return must be a positive ingeteger greater than 0 and less than 251 - you provided {value}"); + } + _numberOfContactListsToReturn = value; + } + } + + /// + /// Get or set the continuation offset when calling list many times to enumerate all your contact lists + /// + /// + /// The return DTO from List contains the current "offset" that you can inject into your next list call + /// to continue the listing process + /// + public long? ContactListOffset { get; set; } = null; + } +} \ No newline at end of file