private static IApiRequest GetApiRequestFromEntity( ITargetProcessClient targetProcessClient, Entity entity, HttpMethod httpMethod) { Ensure.ArgumentNotNull(nameof(targetProcessClient), targetProcessClient); Ensure.ArgumentNotNull(nameof(targetProcessClient.ApiSiteInfo), targetProcessClient.ApiSiteInfo); Ensure.ArgumentNotNull(nameof(targetProcessClient.AuthenticationHandler), targetProcessClient.AuthenticationHandler); var fullPath = GetFullPath(targetProcessClient, httpMethod, entity.Id ?? 0); string data = null; if (httpMethod != HttpMethod.Get) { fullPath = GetFullPath(targetProcessClient, httpMethod); data = GetSerializedEntity(entity); } var request = new ApiRequest { AuthenticationHandler = targetProcessClient.AuthenticationHandler, BaseAddress = fullPath, Data = data, Method = httpMethod, Parameters = targetProcessClient.DefaultQueryParameters, Route = GetRouteText(entity) }; return(request); }
public static IApiResponse <Project> GetNewProject(ITargetProcessClient client) { var project = new Project { Name = $"Sample Project From Code - {DateTime.Now}" }; var data = client.CreateData <Project>(project); return(data); }
private static Uri GetFullPath(ITargetProcessClient targetProcessClient, HttpMethod httpMethod, int id = 0) { Ensure.ArgumentNotNull(nameof(targetProcessClient), targetProcessClient); Ensure.ArgumentNotNull(nameof(targetProcessClient.AuthenticationHandler), targetProcessClient.AuthenticationHandler); Ensure.ArgumentNotNull(nameof(targetProcessClient.AuthenticationHandler.SiteInfo), targetProcessClient.AuthenticationHandler.SiteInfo); if (httpMethod == HttpMethod.Post) { if (targetProcessClient.ApiSiteInfo.Route == TargetProcessRoutes.Route.Undelete.ToString()) { var combinedUrl = ApiSiteHelpers.CombineUrlPaths(targetProcessClient.AuthenticationHandler.SiteInfo.ApiUrl, TargetProcessRoutes.Route.Undelete.ToString()); return(new Uri(combinedUrl)); } return(new Uri(targetProcessClient.AuthenticationHandler.SiteInfo.ApiUrl)); } var fullPath = ApiSiteHelpers.CombineUrlPaths( targetProcessClient.AuthenticationHandler.SiteInfo.ApiUrl, targetProcessClient.ApiSiteInfo.Route); if ((httpMethod == HttpMethod.Get || httpMethod == HttpMethod.Delete) && id > 0) { fullPath = ApiSiteHelpers.CombineUrlPaths(fullPath, id.ToString()); } #if ToDoLaterIfNeeded var excludeList = targetProcessClient.ApiSiteInfo.IsInclude ? new List <string>() : targetProcessClient.ApiSiteInfo.FieldList; var includeList = targetProcessClient.ApiSiteInfo.IsInclude ? targetProcessClient.ApiSiteInfo.FieldList : new List <string>(); #endif var customFilter = targetProcessClient.ApiSiteInfo.CustomFilter; var dictList = new[] { targetProcessClient.DefaultQueryParameters, targetProcessClient.AuthenticationHandler.AuthenticationParameters, targetProcessClient.ApiSiteInfo.Parameters }; var queryParameters = GetParameters(dictList); if (!string.IsNullOrWhiteSpace(customFilter)) { queryParameters += customFilter; } return(new Uri(fullPath + queryParameters)); }
private static IApiRequest GetApiDeleteRequestFromEntityId <T>(ITargetProcessClient targetProcessClient, int id) { Ensure.ArgumentNotNull(nameof(id), id); Ensure.ArgumentNotNull(nameof(targetProcessClient), targetProcessClient); Ensure.ArgumentNotNull(nameof(targetProcessClient.ApiSiteInfo), targetProcessClient.ApiSiteInfo); Ensure.ArgumentNotNull(nameof(targetProcessClient.AuthenticationHandler), targetProcessClient.AuthenticationHandler); var request = new ApiRequest { AuthenticationHandler = targetProcessClient.AuthenticationHandler, BaseAddress = GetFullPath(targetProcessClient, HttpMethod.Delete, id), Data = null, Method = HttpMethod.Delete, Parameters = targetProcessClient.DefaultQueryParameters, Route = GetRouteText <T>(id) }; return(request); }