Skip to content

Commit 215345d

Browse files
authored
Merge branch 'master' into SingleHubAPIKey
2 parents 991f1b3 + 9698bdf commit 215345d

File tree

5 files changed

+133
-0
lines changed

5 files changed

+133
-0
lines changed

HubSpot.NET.Examples/Contacts.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ public class Contacts
1212
{
1313
public static void Example(HubSpotApi api)
1414
{
15+
/**
16+
* Search for a contact
17+
*/
18+
var found = api.Contact.Search<ContactHubSpotModel>(new ContactSearchRequestOptions()
19+
{
20+
Query = ".com"
21+
});
22+
1523
/**
1624
* Create a contact
1725
*/
@@ -95,6 +103,8 @@ public static void Example(HubSpotApi api)
95103
{
96104
Limit = 10
97105
});
106+
107+
98108
}
99109
}
100110
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
using System.Collections.Generic;
2+
using System.Runtime.Serialization;
3+
using HubSpot.NET.Core.Interfaces;
4+
5+
namespace HubSpot.NET.Api.Contact.Dto
6+
{
7+
public class ContactSearchHubSpotModel<T> : IHubSpotModel where T : ContactHubSpotModel, new()
8+
{
9+
10+
/// <summary>
11+
/// Gets or sets the query term used to get the results.
12+
/// </summary>
13+
/// <value>
14+
/// The query term.
15+
/// </value>
16+
/// <remarks>
17+
/// This is a mapping of the "query" prop in the JSON return data from HubSpot
18+
/// </remarks>
19+
[DataMember(Name = "query")]
20+
public string Query { get; set; }
21+
22+
/// <summary>
23+
/// Gets or sets the contacts.
24+
/// </summary>
25+
/// <value>
26+
/// The contacts.
27+
/// </value>
28+
[DataMember(Name = "contacts")]
29+
public IList<T> Contacts { get; set; } = new List<T>();
30+
31+
/// <summary>
32+
/// Gets or sets a value indicating whether more results are available.
33+
/// </summary>
34+
/// <value>
35+
/// <c>true</c> if [more results available]; otherwise, <c>false</c>.
36+
/// </value>
37+
/// <remarks>
38+
/// This is a mapping of the "has-more" prop in the JSON return data from HubSpot
39+
/// </remarks>
40+
[DataMember(Name = "has-more")]
41+
public bool MoreResultsAvailable { get; set; }
42+
43+
/// <summary>
44+
/// Gets or sets the continuation offset.
45+
/// </summary>
46+
/// <value>
47+
/// The continuation offset.
48+
/// </value>
49+
/// <remarks>
50+
/// This is a mapping of the "offset" prop in the JSON reeturn data from HubSpot
51+
/// </remarks>
52+
[DataMember(Name = "offset")]
53+
public long ContinuationOffset { get; set; }
54+
55+
/// <summary>
56+
/// Gets or sets the total.
57+
/// </summary>
58+
/// <value>
59+
/// The total number of contacts found.
60+
/// </value>
61+
/// <remarks>
62+
/// This is a mapping of the "total" prop in the JSON return data from HubSpot
63+
/// </remarks>
64+
[DataMember(Name = "total")]
65+
public long Total { get; set; }
66+
67+
public string RouteBasePath => "/contacts/v1";
68+
69+
public bool IsNameValue => false;
70+
71+
public virtual void ToHubSpotDataEntity(ref dynamic converted)
72+
{
73+
}
74+
75+
public virtual void FromHubSpotDataEntity(dynamic hubspotData)
76+
{
77+
}
78+
}
79+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using HubSpot.NET.Core;
2+
3+
namespace HubSpot.NET.Api.Contact.Dto
4+
{
5+
/// <summary>
6+
/// Options used when querying for a list matching the query term
7+
/// </summary>
8+
public class ContactSearchRequestOptions : ListRequestOptions
9+
{
10+
/// <summary>
11+
/// Gets or set the query term to use when searching
12+
/// </summary>
13+
public string Query { get; set; }
14+
15+
}
16+
}

HubSpot.NET/Api/Contact/HubSpotContactApi.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,32 @@ public void Delete(long contactId)
197197
return data;
198198
}
199199

200+
public ContactSearchHubSpotModel<T> Search<T>(ContactSearchRequestOptions opts = null) where T : ContactHubSpotModel, new()
201+
{
202+
if (opts == null)
203+
{
204+
opts = new ContactSearchRequestOptions();
205+
}
206+
207+
var path = $"{new T().RouteBasePath}/search/query"
208+
.SetQueryParam("q", opts.Query)
209+
.SetQueryParam("count", opts.Limit);
210+
211+
if (opts.PropertiesToInclude.Any())
212+
{
213+
path.SetQueryParam("property", opts.PropertiesToInclude);
214+
}
215+
216+
if (opts.Offset.HasValue)
217+
{
218+
path = path.SetQueryParam("offset", opts.Offset);
219+
}
220+
221+
var data = _client.ExecuteList<ContactSearchHubSpotModel<T>>(path, opts);
222+
223+
return data;
224+
}
225+
200226
/// <summary>
201227
/// Get a list of recently created contacts
202228
/// </summary>

HubSpot.NET/Core/Interfaces/IHubSpotContactApi.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Generic;
2+
using HubSpot.NET.Api.Company;
23
using HubSpot.NET.Api.Contact;
34
using HubSpot.NET.Api.Contact.Dto;
45

@@ -17,5 +18,6 @@ public interface IHubSpotContactApi
1718
void Update<T>(T contact) where T : ContactHubSpotModel, new();
1819
ContactListHubSpotModel<T> RecentlyCreated<T>(ListRecentRequestOptions opts = null) where T : ContactHubSpotModel, new();
1920
ContactListHubSpotModel<T> RecentlyUpdated<T>(ListRecentRequestOptions opts = null) where T : ContactHubSpotModel, new();
21+
ContactSearchHubSpotModel<T> Search<T>(ContactSearchRequestOptions opts = null) where T : ContactHubSpotModel, new();
2022
}
2123
}

0 commit comments

Comments
 (0)