Esempio n. 1
0
        async Task <ListList> IHubSpotListClient.GetAllDynamicAsync(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/dynamic", builder.BuildQuery());

            return(response);
        }
        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);
        }
Esempio n. 3
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);
            }
        }
Esempio n. 4
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}"));
        }
        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);
            }
        }
Esempio n. 6
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);
        }
Esempio n. 7
0
        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);
        }
Esempio n. 8
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);
        }
        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);
            }
        }
Esempio n. 10
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);
        }
Esempio n. 11
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 <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);
        }
Esempio n. 13
0
        public void AddFormSubmissionMode_formSubmissionMode_must_be_a_valid_mode()
        {
            var builder = new HttpQueryStringBuilder();

            Assert.Throws <ArgumentOutOfRangeException>(() => HttpQueryStringBuilderExtensions.AddFormSubmissionMode(builder, (FormSubmissionMode)100));
        }
 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));
 }
        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 HasKey_returns_false_if_empty(HttpQueryStringBuilder sut, string key)
 {
     Assert.That(sut.HasKey(key), Is.False);
 }