public void QueryString_can_be_implicitly_converted_to_string(HttpQueryStringBuilder sut)
        {
            var query = sut.BuildQuery();

            Assume.That(query, Is.InstanceOf <QueryString>());

            string querystring = query;

            Assert.That(querystring, Is.Not.Null);
        }
Example #2
0
        public void AddShowListMemberships_adds_value(bool testValue)
        {
            var builder = new HttpQueryStringBuilder();

            HttpQueryStringBuilderExtensions.AddShowListMemberships(builder, testValue);

            Assume.That(builder.HasKey("showListMemberships"));

            var query = builder.BuildQuery();

            Assert.That(query.Query, Contains.Substring($"showListMemberships={testValue.ToString().ToLower()}"));
        }
Example #3
0
        public void AddFormSubmissionMode_adds_value(FormSubmissionMode mode, string value)
        {
            var builder = new HttpQueryStringBuilder();

            HttpQueryStringBuilderExtensions.AddFormSubmissionMode(builder, mode);

            Assume.That(builder.HasKey("formSubmissionMode"));

            var query = builder.BuildQuery();

            Assert.That(query.Query, Contains.Substring($"formSubmissionMode={value}"));
        }
        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]}"));
            }
        }
Example #5
0
        async Task <ListList> IHubSpotListClient.GetAllAsync(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", builder.BuildQuery());

            return(response);
        }
Example #6
0
        public void AddProperties_adds_all_properties(string fieldName)
        {
            var builder = new HttpQueryStringBuilder();

            var properties = new IProperty[]
            {
                ContactProperties.FirstName
            };

            HttpQueryStringBuilderExtensions.AddProperties(builder, properties, fieldName);

            Assume.That(builder.HasKey(fieldName), Is.True);

            var query = builder.BuildQuery();

            Assert.That(query.Query, Contains.Substring($"{fieldName}={ContactProperties.FirstName.Name}"));
        }
Example #7
0
        async Task <DealList> IHubSpotDealClient.GetAllAsync(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/paged", 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 <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);
        }
Example #10
0
        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);
        }
Example #11
0
        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);
        }
Example #12
0
        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 <Contact> IHubSpotContactClient.GetByUserTokenAsync(string userToken, IReadOnlyList <IProperty> properties, PropertyMode propertyMode, FormSubmissionMode formSubmissionMode, bool showListMemberships)
        {
            if (string.IsNullOrEmpty(userToken))
            {
                throw new ArgumentNullException(nameof(userToken));
            }

            var builder = new HttpQueryStringBuilder();

            builder.AddProperties(properties);
            builder.AddPropertyMode(propertyMode);
            builder.AddFormSubmissionMode(formSubmissionMode);
            builder.AddShowListMemberships(showListMemberships);

            try
            {
                var contact = await _client.GetAsync <Contact>($"/contacts/v1/contact/utk/{userToken}/profile", builder.BuildQuery());

                return(contact);
            }
            catch (HttpException ex) when(ex.StatusCode == HttpStatusCode.NotFound)
            {
                throw new NotFoundException("Contact not found", ex);
            }
        }
Example #14
0
        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);
        }
        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 <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 <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);
        }
Example #18
0
        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());
        }
Example #19
0
        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 <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);
        }
Example #21
0
        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 <Contact> IHubSpotContactClient.GetByIdAsync(long contactId, IReadOnlyList <IProperty> properties, PropertyMode propertyMode, FormSubmissionMode formSubmissionMode, bool showListMemberships)
        {
            var builder = new HttpQueryStringBuilder();

            builder.AddProperties(properties);
            builder.AddPropertyMode(propertyMode);
            builder.AddFormSubmissionMode(formSubmissionMode);
            builder.AddShowListMemberships(showListMemberships);

            try
            {
                var contact = await _client.GetAsync <Contact>($"/contacts/v1/contact/vid/{contactId}/profile", builder.BuildQuery());

                return(contact);
            }
            catch (HttpException ex) when(ex.StatusCode == HttpStatusCode.NotFound)
            {
                throw new NotFoundException("Contact not found", ex);
            }
        }
Example #23
0
        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);
            }
        }
        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);
        }
Example #25
0
        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 <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);
        }
Example #27
0
        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);
        }