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);
        }
        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 <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);
            }
        }
        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);
        }
Esempio n. 5
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. 6
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);
        }
        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. 8
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);
        }