/// <summary>
        /// get a contact by id
        /// </summary>
        /// <typeparam name="T">type of contact model</typeparam>
        /// <param name="id">id of contact to return</param>
        /// <returns>contact data</returns>
        public async Task <T> GetEngagement <T>(long id)
            where T : HubSpotEngagementResult
        {
            JObject response = await rest.Get <JObject>($"/engagements/v1/engagements/{id}");

            return(ToEngagementResult <T>(response));
        }
Beispiel #2
0
        /// <summary>
        /// lists all deals and returns a page of the result
        /// </summary>
        /// <typeparam name="T">type of deal model</typeparam>
        /// <param name="offset">offset to use to get a specific result page (optional)</param>
        /// <param name="properties">properties to include in result</param>
        /// <returns>one page of deal list response</returns>
        public async Task <PageResponse <T> > ListPage <T>(long?offset = null, params string[] properties)
            where T : HubSpotDeal
        {
            EntityModel model = registry.Get(typeof(T));

            JObject response = await rest.Get <JObject>("deals/v1/deal/paged", GetListParameters(offset, properties).ToArray());

            return(new PageResponse <T> {
                Offset = response.Value <bool>("hasMore") ? response.Value <long?>("offset") : null,
                Data = response.GetValue("deals").OfType <JObject>().Select(d => ToDeal <T>(d, model)).ToArray()
            });
        }
Beispiel #3
0
        /// <summary>
        /// lists all companies
        /// </summary>
        /// <typeparam name="T">type of company to return</typeparam>
        /// <param name="properties">properties to include in result</param>
        /// <returns>list of all companies</returns>
        public async Task <T[]> List <T>(params string[] properties)
            where T : HubSpotCompany
        {
            EntityModel model  = registry.Get(typeof(T));
            List <T>    result = new List <T>();
            long?       offset = null;

            do
            {
                JObject response = await rest.Get("companies/v2/companies/paged", GetListParameters(offset, properties).ToArray());

                foreach (JObject companyobject in response.GetValue("companies").OfType <JObject>())
                {
                    result.Add(ToCompany <T>(companyobject, model));
                }

                if (response.Value <bool>("has-more"))
                {
                    offset = response.Value <long>("offset");
                }
                else
                {
                    break;
                }
            } while (true);

            return(result.ToArray());
        }
Beispiel #4
0
        /// <summary>
        /// lists a page of contacts
        /// </summary>
        /// <typeparam name="T">type of contact model</typeparam>
        /// <param name="offset">page offset</param>
        /// <param name="properties">properties to include in response</param>
        /// <returns>a page of contacts</returns>
        public async Task <PageResponse <T> > ListPage <T>(long?offset = null, int?count = null, params string[] properties)
            where T : HubSpotContact
        {
            EntityModel model = models.Get(typeof(T));

            JObject response = await rest.Get <JObject>("contacts/v1/lists/all/contacts/all", GetListParameters(offset, count ?? 100, properties).ToArray());

            var hasMore = response.Value <bool>("has-more");

            return(new PageResponse <T>
            {
                HasMore = hasMore,
                Offset = hasMore ? response.Value <long?>("vid-offset") : null,
                Data = response.GetValue("contacts").OfType <JObject>().Select(d => d.ToContact <T>(model)).ToArray()
            });
        }
Beispiel #5
0
        /// <inheritdoc />
        public async Task <T> GetTicket <T>(long ticketid)
            where T : HubspotTicket
        {
            EntityModel ticketmodel = models.Get(typeof(T));
            JObject     response    = await restclient.Get <JObject>($"crm-objects/v1/objects/tickets/{ticketid}");

            return(response.ToEntity <T>(ticketmodel));
        }
        /// <summary>
        /// Get the IDs of objects associated with the given object, based on the specified association type
        /// </summary>
        /// <param name="objectid">id of which to list associations</param>
        /// <param name="type">type of assocation to list</param>
        /// <param name="offset">page token used to get next page in multipage result (optional)</param>
        /// <returns>one page of list results</returns>
        public async Task <PageResponse <long> > ListPage(long objectid, AssociationType type, long?offset = null)
        {
            JObject response = await rest.Get <JObject>($"crm-associations/v1/associations/{objectid}/HUBSPOT_DEFINED/{(int) type}", GetListParameters(offset).ToArray());

            return(new PageResponse <long> {
                Offset = response.Value <bool>("hasMore") ? response.Value <long?>("offset") : null,
                Data = response.ContainsKey("results") ? response["results"].Values <long>().ToArray() : new long[0]
            });
        }
        public async Task <HubSpotBlogPostList <T> > ListPage <T>(long?offset = null, int?limit = null, string state = "PUBLISHED", params KeyValuePair <string, string>[] properties)  where T : HubSpotBlogPost
        {
            JObject response = await _rest.Get <JObject>("content/api/v2/blog-posts", GetListParameters(offset, limit, state, "-publish_date", properties).ToArray());

            return(response.ToObject <HubSpotBlogPostList <T> >());
        }
Beispiel #8
0
        /// <summary>
        /// Returns all of the owners that exist inside of HubSpot
        /// </summary>
        /// <param name="email">filters list for owners with specific e-mails (optional)</param>
        /// <param name="includeinactive">includes inactive owners in result</param>
        /// <returns></returns>
        public async Task <Owner[]> List(string email = null, bool includeinactive = false)
        {
            JArray response = await rest.Get <JArray>("owners/v2/owners/", GetListParameters(email, includeinactive).ToArray());

            return(response.ToObject <Owner[]>());
        }