async Task <ContactList> IHubSpotContactClient.GetRecentlyCreatedAsync(IReadOnlyList <IProperty> properties, PropertyMode propertyMode, FormSubmissionMode formSubmissionMode, bool showListMemberships, int count, long?contactOffset, DateTimeOffset?timeOffset) { if (count > 100) { throw new ArgumentOutOfRangeException(nameof(count), "Up to 100 contacts can be requested at the same time"); } var builder = new HttpQueryStringBuilder(); builder.AddProperties(properties); builder.AddPropertyMode(propertyMode); builder.AddFormSubmissionMode(formSubmissionMode); builder.AddShowListMemberships(showListMemberships); builder.Add("count", count.ToString()); if (contactOffset.HasValue) { builder.Add("vidOffset", contactOffset.Value.ToString()); } if (timeOffset.HasValue) { builder.Add("timeOffset", timeOffset.Value.ToUnixTimeMilliseconds().ToString()); } var list = await _client.GetAsync <ContactList>("/contacts/v1/lists/all/contacts/recent", builder.BuildQuery()); return(list); }
async Task <SearchResponse> IHubSpotContactClient.SearchAsync(string query, IReadOnlyList <IProperty> properties, int count, long?contactOffset) { if (string.IsNullOrEmpty(query)) { throw new ArgumentNullException(nameof(query)); } if (count > 100) { throw new ArgumentOutOfRangeException(nameof(count), "Up to 100 contacts can be requested at the same time"); } var builder = new HttpQueryStringBuilder(); builder.Add("q", query); builder.AddProperties(properties); builder.Add("count", count.ToString()); if (contactOffset.HasValue) { builder.Add("offset", contactOffset.Value.ToString()); } var response = await _client.GetAsync <SearchResponse>("/contacts/v1/search/query", builder.BuildQuery()); return(response); }
async Task <PaginatedResult <User> > IUserComUsersClient.FindByDateAsync(DateSearchType searchType, DateTime min, DateTime max) { var builder = new HttpQueryStringBuilder(); builder.Add("search", searchType.ToString().ToSnakeCase()); builder.Add("min", new DateTimeOffset(min.ToUniversalTime()).ToUnixTimeSeconds()); builder.Add("max", new DateTimeOffset(max.ToUniversalTime()).ToUnixTimeSeconds()); var result = await SendAsync <dynamic>(HttpMethod.Get, $"{USER_RESOURCE}/search/", builder.BuildQuery()); var paginatedResult = CreatePaginatedResult <User>(result); return(paginatedResult); }
async Task <ContactIdList> IHubSpotCompanyClient.GetContactIdsInCompanyAsync(long companyId, int count, long?companyOffset) { var builder = new HttpQueryStringBuilder(); builder.Add("count", count.ToString()); if (companyOffset.HasValue) { builder.Add("vidOffset", companyOffset.Value.ToString()); } var result = await _client.GetAsync <ContactIdList>($"/companies/v2/companies/{companyId}/vids", builder.BuildQuery()); return(result); }
async Task <PagedList <Company> > IHubSpotCompanyClient.GetRecentlyCreatedAsync(int count, long?offset) { var builder = new HttpQueryStringBuilder(); builder.Add("count", count.ToString()); if (offset.HasValue) { builder.Add("offset", offset.Value.ToString()); } var result = await _client.GetAsync <PagedList <Company> >("/companies/v2/companies/recent/created", builder.BuildQuery()); return(result); }
async Task <ListList> IHubSpotListClient.GetAllStaticAsync(int count, long?offset) { if (count > 250) { throw new ArgumentOutOfRangeException(nameof(count), "Up to 250 lists can be requested at the same time"); } var builder = new HttpQueryStringBuilder(); builder.Add("count", count); builder.Add("offset", offset); var response = await _client.GetAsync <ListList>("/contacts/v1/lists/static", builder.BuildQuery()); return(response); }
public void Same_key_can_be_added_more_than_once(HttpQueryStringBuilder sut, string key, string[] values) { foreach (var value in values) { sut.Add(key, value); } }
async Task <IReadOnlyDictionary <long, Contact> > IHubSpotContactClient.GetManyByIdAsync(IReadOnlyList <long> contactIds, IReadOnlyList <IProperty> properties, PropertyMode propertyMode, FormSubmissionMode formSubmissionMode, bool showListMemberships, bool includeDeletes) { if (contactIds == null || contactIds.Count == 0) { return(new Dictionary <long, Contact>()); } if (contactIds.Count >= 100) { throw new ArgumentOutOfRangeException(nameof(contactIds), "Up to 100 contacts can be requested at the same time"); } var builder = new HttpQueryStringBuilder(); foreach (var id in contactIds) { builder.Add("vid", id.ToString()); } builder.AddProperties(properties); builder.AddPropertyMode(propertyMode); builder.AddFormSubmissionMode(formSubmissionMode); builder.AddShowListMemberships(showListMemberships); var contacts = await _client.GetAsync <Dictionary <long, Contact> >("/contacts/v1/contact/vids/batch/", builder.BuildQuery()); return(contacts); }
public static void AddFormSubmissionMode(this HttpQueryStringBuilder builder, FormSubmissionMode formSubmissionMode) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } builder.Add("formSubmissionMode", GetFormSubmissionMode(formSubmissionMode));
async Task <CompanyList> IHubSpotCompanyClient.GetAllAsync(IReadOnlyList <IProperty> properties, IReadOnlyList <IProperty> propertiesWithHistory, int limit, long?companyOffset) { var builder = new HttpQueryStringBuilder(); builder.AddProperties(properties, "properties"); builder.AddProperties(propertiesWithHistory, "propertiesWithHistory"); builder.Add("limit", limit.ToString()); if (companyOffset.HasValue) { builder.Add("offset", companyOffset.Value.ToString()); } var result = await _client.GetAsync <CompanyList>("/companies/v2/companies/paged", builder.BuildQuery()); return(result); }
public static void AddShowListMemberships(this HttpQueryStringBuilder builder, bool showListMemberships) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } builder.Add("showListMemberships", showListMemberships ? "true" : "false"); }
async Task <DealList> IHubSpotDealClient.FindByCompanyAsync(long companyId, IReadOnlyList <IProperty> properties, IReadOnlyList <IProperty> propertiesWithHistory, bool includeAssociations, int limit, long?offset) { var builder = new HttpQueryStringBuilder(); builder.AddProperties(properties, "properties"); builder.AddProperties(propertiesWithHistory, "propertiesWithHistory"); builder.Add("limit", limit.ToString()); builder.Add("includeAssociations", includeAssociations); if (offset.HasValue) { builder.Add("offset", offset.Value.ToString()); } var result = await _client.GetAsync <DealList>($"/deals/v1/deal/associated/COMPANY/{companyId}/paged", builder.BuildQuery()); return(result); }
async Task <User> IUserComUsersClient.FindByEmailAsync(string email) { var builder = new HttpQueryStringBuilder(); builder.Add("email", email); var result = await SendAsync <User>(HttpMethod.Get, $"{USER_RESOURCE}/search/", builder.BuildQuery()); return(result); }
async Task <User> IUserComUsersClient.FindByPhoneNumberAsync(string phoneNumber) { var builder = new HttpQueryStringBuilder(); builder.Add("phone_number", phoneNumber); var result = await SendAsync <User>(HttpMethod.Get, $"{USER_RESOURCE}/search/", builder.BuildQuery()); return(result); }
async Task <ContactList> IHubSpotListClient.GetContactsInListAsync(long listId, IReadOnlyList <IProperty> properties, PropertyMode propertyMode, FormSubmissionMode formSubmissionMode, bool showListMemberships, int count, long?contactOffset) { if (count > 100) { throw new ArgumentOutOfRangeException(nameof(count), "Up to 100 contacts can be requested at the same time"); } var builder = new HttpQueryStringBuilder(); builder.AddProperties(properties); builder.AddPropertyMode(propertyMode); builder.AddFormSubmissionMode(formSubmissionMode); builder.AddShowListMemberships(showListMemberships); builder.Add("count", count.ToString()); builder.Add("vidOffset", contactOffset); var list = await _client.GetAsync <ContactList>($"/contacts/v1/lists/{listId}/contacts/all", builder.BuildQuery()); return(list); }
async Task <PagedList <Deal> > IHubSpotDealClient.GetRecentlyCreatedAsync(DateTimeOffset?since, bool includePropertyVersions, int count, long?offset) { var builder = new HttpQueryStringBuilder(); builder.Add("count", count.ToString()); builder.Add("includePropertyVersions", includePropertyVersions); if (since.HasValue) { builder.Add("since", since.Value.ToUnixTimeMilliseconds()); } if (offset.HasValue) { builder.Add("offset", offset.Value.ToString()); } var result = await _client.GetAsync <PagedList <Deal> >("/deals/v1/deal/recent/modified", builder.BuildQuery()); return(result); }
async Task <AssociationIdList> IHubSpotCrmAssociationClient.GetAllAsync(long objectId, AssociationType associationType, int limit, long?offset) { if (limit > 100) { throw new ArgumentOutOfRangeException(nameof(limit), "Up to 100 items can be requested at the same time"); } var builder = new HttpQueryStringBuilder(); builder.Add("limit", limit); if (offset.HasValue) { builder.Add("offset", offset.Value); } string path = $"/crm-associations/v1/associations/{objectId}/HUBSPOT_DEFINED/{associationType.Id}"; IQueryString query = builder.BuildQuery(); var list = await _client.SendAsync <AssociationIdList>(HttpMethod.Get, path, query); return(list); }
async Task <IReadOnlyList <Owner> > IHubSpotOwnerClient.GetManyAsync(string email) { var builder = new HttpQueryStringBuilder(); if (email != null) { builder.Add("email", email); } var response = await _client.GetAsync <IReadOnlyList <Owner> >("/owners/v2/owners/", builder.BuildQuery()).ConfigureAwait(false); return(response); }
async Task IHubSpotDealClient.RemoveAssociationToCompaniesAsync(long dealId, IReadOnlyList <long> ids) { if (ids == null || ids.Count == 0) { return; } var builder = new HttpQueryStringBuilder(); foreach (var id in ids) { builder.Add("id", id); } await _client.DeleteAsync($"/deals/v1/deal/{dealId}/associations/COMPANY", query : builder.BuildQuery()); }
async Task IHubSpotDealClient.AssociateContactsAsync(long dealId, IReadOnlyList <long> ids) { if (ids == null || ids.Count == 0) { return; } var builder = new HttpQueryStringBuilder(); foreach (var id in ids) { builder.Add("id", id); } await _client.PutAsync($"/deals/v1/deal/{dealId}/associations/CONTACT", query : builder.BuildQuery()); }
async Task <PaginatedResult <User> > IUserComUsersClient.FilterByCustomAttributesAsync(IEnumerable <CustomAttributeFilter> filters) { var builder = new HttpQueryStringBuilder(); foreach (var filter in filters) { var param = filter.ToQueryParam(); builder.Add(param.key, param.value); } var result = await SendAsync <dynamic>(HttpMethod.Get, $"{USER_RESOURCE}/search/", builder.BuildQuery()); var paginatedResult = CreatePaginatedResult <User>(result); return(paginatedResult); }
public void BuildQuery_returns_query_with_added_items(HttpQueryStringBuilder sut, string[] keys, string[] values) { Assume.That(keys.Length, Is.EqualTo(values.Length)); for (int i = 0; i < keys.Length; i++) { sut.Add(keys[i], values[i]); } string querystring = sut.BuildQuery(); for (int i = 0; i < keys.Length; i++) { Assert.That(querystring, Contains.Substring($"{keys[i]}={values[i]}")); } }
async Task <Deal> IHubSpotDealClient.GetByIdAsync(long dealId, bool includePropertyVersions) { var builder = new HttpQueryStringBuilder(); builder.Add("includePropertyVersions", includePropertyVersions); try { var result = await _client.GetAsync <Deal>($"/deals/v1/deal/{dealId}", builder.BuildQuery()); return(result); } catch (HttpException ex) when(ex.StatusCode == HttpStatusCode.NotFound) { throw new NotFoundException("Deal not found", ex); } }
public static void AddProperties(this HttpQueryStringBuilder builder, IEnumerable <IProperty> properties, string fieldName = "property") { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } if (string.IsNullOrEmpty(fieldName)) { throw new ArgumentNullException(nameof(fieldName)); } foreach (var property in properties ?? Array.Empty <IProperty>()) { builder.Add(fieldName, property.Name); } }
async Task <ListList> IHubSpotListClient.GetManyByIdAsync(IReadOnlyList <long> listIds) { if (listIds == null || listIds.Count == 0) { return(ListList.Empty); } var builder = new HttpQueryStringBuilder(); foreach (var id in listIds) { builder.Add("listId", id); } var response = await _client.GetAsync <ListList>("/contacts/v1/lists/batch", builder.BuildQuery()); return(response); }
public void HasKey_returns_true_if_key_is_added(HttpQueryStringBuilder sut, string key, string value) { sut.Add(key, value); Assert.That(sut.HasKey(key), Is.True); }
public void Add_throws_if_value_is_null(HttpQueryStringBuilder sut, string key) { Assert.Throws <ArgumentNullException>(() => sut.Add(key, null)); }
public void Add_throws_if_key_is_null(HttpQueryStringBuilder sut, string value) { Assert.Throws <ArgumentNullException>(() => sut.Add(null, value)); }