/// <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> internal string PathResolver(ILineItemHubSpotEntity entity, HubSpotAction action) { switch (action) { case HubSpotAction.Create: return($"{entity.RouteBasePath}/line_items"); case HubSpotAction.Get: return($"{entity.RouteBasePath}/line_items/:lineItemId:"); case HubSpotAction.Update: return($"{entity.RouteBasePath}/line_items/:lineItemId:"); case HubSpotAction.Delete: return($"{entity.RouteBasePath}/line_items/:lineItemId:"); case HubSpotAction.List: return($"{entity.RouteBasePath}/line_items/paged"); case HubSpotAction.CreateBatch: return($"{entity.RouteBasePath}/line_items/batch-create"); case HubSpotAction.DeleteBatch: return($"{entity.RouteBasePath}/line_items/batch-delete"); case HubSpotAction.UpdateBatch: return($"{entity.RouteBasePath}/line_items/batch-update"); case HubSpotAction.ReadBatch: return($"{entity.RouteBasePath}/line_items/batch-read"); default: throw new ArgumentOutOfRangeException(nameof(action), action, null); } }
public Task <T> CreateAsync <T>(ILineItemHubSpotEntity entity) where T : IHubSpotEntity, new() { Logger.LogDebug("Line Item CreateAsync"); var path = PathResolver(entity, HubSpotAction.Create); var request = _serializer.SerializeEntityToNameValueList(entity); return(SendRequestAsync(path, HttpMethod.Post, request, (response) => { return _serializer.DeserializeEntity <T>(response); })); }
public Task <T> UpdateAsync <T>(ILineItemHubSpotEntity entity) where T : IHubSpotEntity, new() { Logger.LogDebug("Line Item update w. id: {0}", entity.Id); if (entity.Id < 1) { throw new ArgumentException("Line Item entity must have an id set!"); } var path = PathResolver(entity, HubSpotAction.Update) .Replace(":lineItemId:", entity.Id.ToString()); var request = _serializer.SerializeEntityToNameValueList(entity); return(SendRequestAsync(path, HttpMethod.Put, request, (response) => { return _serializer.DeserializeEntity <T>(response); })); }