예제 #1
0
        /// <summary>
        /// Resolve a hubspot API path based off the entity and opreation that is about to happen
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="action"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentOutOfRangeException"></exception>
        public string PathResolver(IContactHubSpotEntity entity, HubSpotAction action)
        {
            switch (action)
            {
            case HubSpotAction.Create:
                return($"{entity.RouteBasePath}/contact");

            case HubSpotAction.Get:
                return($"{entity.RouteBasePath}/contact/vid/:contactId:/profile");

            case HubSpotAction.GetByEmail:
                return($"{entity.RouteBasePath}/contact/email/:contactEmail:/profile");

            case HubSpotAction.List:
                return($"{entity.RouteBasePath}/lists/all/contacts/all");

            case HubSpotAction.Update:
                return($"{entity.RouteBasePath}/contact/vid/:contactId:/profile");

            case HubSpotAction.Delete:
                return($"{entity.RouteBasePath}/contact/vid/:contactId:");

            default:
                throw new ArgumentOutOfRangeException(nameof(action), action, null);
            }
        }
예제 #2
0
        /// <summary>
        /// Creates the contact entity asyncrhounously.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task <T> CreateAsync <T>(IContactHubSpotEntity entity) where T : IHubSpotEntity, new()
        {
            Logger.LogDebug("Contact CreateAsync");
            var path = PathResolver(entity, HubSpotAction.Create);
            var data = await PostAsync <T>(path, entity);

            return(data);
        }
예제 #3
0
        /// <summary>
        /// Creates or updates the contact entity asyncrhounously.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task <T> CreateOrUpdateAsync <T>(IContactHubSpotEntity entity) where T : IHubSpotEntity, new()
        {
            Logger.LogDebug("Contact CreateOrUpdateAsync");
            var path = PathResolver(entity, HubSpotAction.CreateOrUpdate)
                       .Replace(":contactemail:", WebUtility.UrlEncode(entity.Email));
            var data = await PostAsync <T>(path, entity);

            return(data);
        }
예제 #4
0
        public async Task UpdateAsync(IContactHubSpotEntity contact)
        {
            Logger.LogDebug("Contact update w. id: {0}", contact.Id);
            if (contact.Id < 1)
            {
                throw new ArgumentException("Contact entity must have an id set!");
            }
            var path = PathResolver(contact, HubSpotAction.Update)
                       .Replace(":contactId:", contact.Id.ToString());

            await PostAsync <ContactHubSpotEntity>(path, contact);
        }