Ejemplo n.º 1
0
        /// <summary>
        /// Creates the deal entity asynchronously.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task <T> CreateAsync <T>(IDealHubSpotEntity entity) where T : IHubSpotEntity, new()
        {
            Logger.LogDebug("Deal CreateAsync");
            var path = PathResolver(entity, HubSpotAction.Create);
            var data = await PostAsync <T>(path, entity);

            return(data);
        }
Ejemplo n.º 2
0
        public async Task <T> UpdateAsync <T>(IDealHubSpotEntity entity) where T : IHubSpotEntity, new()
        {
            Logger.LogDebug("Deal update w. id: {0}", entity.Id);
            if (entity.Id < 1)
            {
                throw new ArgumentException("Deal entity must have an id set!");
            }
            var path = PathResolver(entity, HubSpotAction.Update)
                       .Replace(":dealId:", entity.Id.ToString());

            var data = await PutAsync <T>(path, entity);

            return(data);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Resolve a hubspot API path based off the entity and operation that is about to happen
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="action"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentOutOfRangeException"></exception>
        public string PathResolver(IDealHubSpotEntity entity, HubSpotAction action)
        {
            switch (action)
            {
            case HubSpotAction.Create:
                return($"{entity.RouteBasePath}/deal");

            case HubSpotAction.Get:
                return($"{entity.RouteBasePath}/deal/:dealId:");

            case HubSpotAction.Update:
                return($"{entity.RouteBasePath}/deal/:dealId:");

            case HubSpotAction.Delete:
                return($"{entity.RouteBasePath}/deal/:dealId:");

            default:
                throw new ArgumentOutOfRangeException(nameof(action), action, null);
            }
        }