/// <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(ICompanyHubSpotEntity entity, HubSpotAction action) { switch (action) { case HubSpotAction.Create: return($"{entity.RouteBasePath}/companies"); case HubSpotAction.Get: return($"{entity.RouteBasePath}/companies/:companyId:"); case HubSpotAction.GetByEmail: return($"{entity.RouteBasePath}/domains/:domain:/companies"); case HubSpotAction.List: return($"{entity.RouteBasePath}/companies/paged"); case HubSpotAction.Update: return($"{entity.RouteBasePath}/companies/:companyId:"); case HubSpotAction.Delete: return($"{entity.RouteBasePath}/companies/:companyId:"); default: throw new ArgumentOutOfRangeException(nameof(action), action, null); } }
/// <summary> /// Creates the Company entity asynchronously. /// </summary> /// <param name="entity">The entity.</param> /// <returns></returns> /// <exception cref="NotImplementedException"></exception> public async Task <T> CreateAsync <T>(ICompanyHubSpotEntity entity) where T : IHubSpotEntity, new() { Logger.LogDebug("Company CreateAsync"); var path = PathResolver(entity, HubSpotAction.Create); var data = await PostAsync <T>(path, entity); return(data); }
public async Task <T> UpdateAsync <T>(ICompanyHubSpotEntity entity) where T : IHubSpotEntity, new() { Logger.LogDebug("Company update w. id: {0}", entity.Id); if (entity.Id < 1) { throw new ArgumentException("Company entity must have an id set!"); } var path = PathResolver(entity, HubSpotAction.Update) .Replace(":companyId:", entity.Id.ToString()); var data = await PutAsync <T>(path, entity); return(data); }